This function is similar to the preg_match_all() function, but this function will match all content that meets the requirements and store it in a string.
$mode='/[89]/';//match 8 or 9
$str="dj33f44k88dsjk10903990sjdfdk";
preg_match_all($mode,$str,$arr);
print_r($arr);
?>
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] )
Replace related content through regular expressions, similar to the str_replace string replacement learned before, but the function is stronger than it.
Features: 1. The replacement content can be a regular expression or an array regular expression
2. The replacement content can be solved by using the modifier e to replace the execution content
Usage: to replace some more complex content, and can also be used for content conversion
Example 1 - Array regularization:
[php]
$mode=array('/{title}/','/{author}/','/{url}/');
$re=array("code cloud","qianshou","http://codecloud.duapp.com/");
$str="Title: {title}
Author: {author}
Address: {url}";
echo "
";
if($tag=preg_replace($mode,$re,$str)){
echo $tag;
}else{
echo "Replacement failed!";
}
?>
Output:
[html]
Title: code cloud
Author: qianshou
Address: http://codecloud.duapp.com/
Example 2 - Replacement of ubb code:
[php]
$str="Welcome to my blog: [url]http://blog.csdn.net/qsyzb[/url]";
$re=preg_replace('/[url](.*)[/url]/',"
\1",$ str);
echo "
".$re."
";
?>
Output:
[html
preg_split ( string pattern, string subject [, intlimit [, int flags]] )
Cut related content through regular expressions, similar to the explode cutting function learned before, but explode can only cut in one way and has limitations.
Example:
[php]
$mode='/[,.#]/';
$str='one,two.three#four';
if($tag=preg_split($mode,$str)){
print_r($tag);
}else{
echo "Replacement failed!";
}
?>
Output:
[html]
Array
(
[0] => one
[1] => two
[2] => three
[3] => four
)
http://www.bkjia.com/PHPjc/477144.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477144.htmlTechArticlepreg_match(); //Used for regular expression matching, and only matched once preg_match_all();// Used for regular expression matching, all matching rules will be matched preg_replace(); //Regular...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn