Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How PHP uses preg_replace ()

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how PHP uses preg_replace ()". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "how PHP uses preg_replace ()".

Preg_replace ()

Function prototype: mixed preg_replace (mixed $pattern, mixed $replacement, mixed $subject [, int $limit])

Preg_replace is more powerful than ereg_replace. Arrays can be used for the first three parameters; the fourth parameter, $limit, sets the number of replacements, which defaults to all substitutions. Code 6.7 is an application example of array substitution.

Code 6.7 Array replacement

The code is as follows:

The output is as follows.

Name: Thomas Ching ", Email: tom@emailaddress.com Address: No.5, Wilson St., New York, U.S.A

The pattern modifier "e" can be used in preg_replace 's regular expressions. Its purpose is to use the matching result as an expression and can be recalculated. For example:

The code is as follows:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report