Get the App
SLTechnology News&Howtos  ›  Development  › 

How PHP uses preg_replace ()

Shulou Source: shulou.com Published: 2022-06-01 02:39:31 09月22日 Update

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:

Tags: Code pattern result content function character array article expression output parameter string lowercase regular U.S.A learning help powerful three function Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia OPPO Reno MySQL Huawei Xiaomi