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 (mode, stringsubject, arraymatches)
Preg_match (); // used for regular expression matching, and only matches preg_match_all () once; // 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)
Preg_match (); // used for regular expression matching only once
Preg_match_all (); // used for regular expression matching. All matching rules are matched.
Preg_replace (); // Regular Expression replacement function
Preg_splite (); // 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 the matching result array.
Example:
Output:
Array ( [0] => 9 )
Preg_match_all (mode, string subject, arraymatches)
This function is similar to the preg_match_all () function, but it matches all the required content and stores it in a string.
Example:
Output:
Array ( [0] => Array ( [0] => 8 [1] => 8 [2] => 9 [3] => 9 [4] => 9 ) )
Preg_replace (mixed pattern, mixed replacement, mixed subject [, int limit])
Use regular expressions to replace related content, similar to the previously learned str_replace string replacement, but the function is better than it.
Features: 1. The replacement content can be a regular or array regular
2. The replacement content can be replaced by the modifier e.
Purpose: replace some complicated content and use it for content conversion.
Example 1 -- array regular:
Author: {author}
Url: {url} "; echo"
"; If ($ tag = preg_replace ($ mode, $ re, $ str) {echo $ tag;} else {echo" cannot be replaced! ";}?>
Output:
Title: code cloud Author: qianshou address: http://codecloud.duapp.com/
Example 2 -- replace the ubb code:
Output:
Welcome to my blog: http://blog.csdn.net/qsyzb
Preg_split (string pattern, string subject [, intlimit [, int flags])
Regular expressions are used to cut related content. Similar to the previously learned explode cut function, explode only has limitations in one way.
Example:
Output:
Array( [0] => one [1] => two [2] => three [3] => four)