These two functions are described and used in detail in the php manual, but the parameters and styles are not clear, the function format is described in detail and usage of these two functions in the php manual, but the parameters and styles are not clear. the Function format is as follows:
Eregi_replace (string pattern, string replacement, string)
Preg_replace (mixed pattern, mixed replacement, mixed subject [, int limit [, int & count])
For example, the usage of UBB and YBB Code is as follows:
$ Str = eregi_replace ("\ [url] http: // ([^ \ [] *) \ [/url \]", "\ 1 ", $ str );
$ Text = preg_replace ("! (\ [Url =) (http | https | ftp) (: // \ S ++ ?) (\]) (. + ?) (\ [/Url \])! I "," \ 5 ", $ text)
The preg_replace () function uses Perl-compatible regular expression syntax, which is usually a faster alternative than ereg_replace.
Form or (from PHP 4.0.4) $ n form of reverse reference, the latter is preferred. Each such reference will be replaced with the text that matches the child pattern in the nth captured parentheses
N can be from 0 to 99, where \ 0 or $0 indicates the text matched by the entire mode. Count left parentheses from left to right (starting from 1) to obtain the number of child modes
Example: reverse reference followed by a number
$ String = "April 15,200 8 "; $ Pattern = "/(\ w +) (\ d +), (\ d +)/I "; $ Replacement = "\$ {1} 1, \ $3 "; Print preg_replace ($ pattern, $ replacement, $ string ); ?> |
/* Output
Preg_replace () does not know whether a reverse reference of \ 1 is followed by a number 1 or a reverse reference of \ 11. The solution in this example is to use \ $ {1} 1
April1, 2008
*/