Code usage comparison between eregi_replace and preg_replace Functions

Source: Internet
Author: User

Eregi_replace (string pattern, string replacement, string)
Preg_replace (mixed pattern, mixed replacement, Mixed Subject [, int limit [, Int & COUNT])
I know the basic definitions of the above two functions.
But I don't understand the style or Parameter definition in it.
For example, the usage of UBB and ybb code is as follows:
$ STR = eregi_replace ("\ [url] http: // ([^ \ [] *) \ [/url \]", "<a href = \" http: // \\ 1 \ "target = \" _ blank \ ">\\ 1 </a>", $ Str );
$ Text = preg_replace ("! (\ [Url =) (HTTP | HTTPS | FTP) (: // \ s ++ ?) (\]) (. + ?) (\ [/Url \])! I "," <a href = '\ 2 \ 3' target = '_ blank'> \ 5 </a> ", $ text );
Who can explain the meaning of the symbols in the solution?
I believe that many people will just copy and use it.
But if you do not understand what you mean, you cannot write your own program,
The function has been used.
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 1. Reverse reference followed by a number CopyCode The Code is as follows: <? PHP
$ String = "April 15,200 3 ";
$ 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, 2003
*/
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.