Regular expression function preg _ in PHP _

Source: Internet
Author: User
Preg_match (); used for regular expression matching, and only match once preg_match_all (); used for regular expression matching, all compliant with the rule will be matched preg_replace (); regular expression replacement function preg_splite (); regular expression division function preg_match (); // used for regular expression matching, and only matches preg_match_all (); // used for regular expression matching, preg_replace () will be matched for all compliant rules; // the regular expression replacement function preg_splite (); // the regular expression division function preg_match (mode, string subject, arraymatches) here, mode is a regular rule, string subject is the string to be matched, and arraymatches is an array of matched results. example: [php] Output: [html] Array ([0] => 9) preg_match_all (mode, string subject, arraymatches). This function is similar to the preg_match_all () function, however, this function will match all the required content and store it in a string. Example: [php] Output: [html] Array ([0] => Array ([0] => 8 [1] => 8 [2] => 9 [3] => 9 [4] => 9 )) preg_replace (mixed pattern, mixed replacement, mixed subject [, int limit]) replaces the relevant content using a regular expression. it is similar to the str_replace string that has been learned before, but the function is better than it. Features: 1. the content to be replaced can be a regular expression or an array regular expression. 2. the content to be replaced can be replaced by the modifier e. The purpose of the content to be replaced is to replace some complicated content, it can also be used for content Conversion. example 1 -- array regular: [php] Author: {author}
Url: {url} "; echo" "; If ($ tag = preg_replace ($ mode, $ re, $ str) {echo $ tag;} else {echo" cannot be replaced! ";}?> Output: [html] Title: code cloud author: qianshou address: http://codecloud.duapp.com/Example 2 -- replacement of ubb code: [php] Output: [html welcome to my blog: http://blog.csdn.net/qsyzb preg_split (string pattern, string subject [, intlimit [, int flags]) using regular expressions to cut related content, similar to the previously learned explode cut function, explode only has limitations in one way. Example: [php] Output: [html] Array ([0] => one [1] => two [2] => three [3] => four)

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.