Php regular function 2 preg_match_all ???? Let's continue with the perl-style regular function preg_match_all .???? Function prototype :? & Lt ;? Php & gt; preg_match_all ($ pattern, $ subject, array & amp; $ matchesnull, $ flagsnull, $ offset php regular function 2 preg_match_all
? ? ? ? Let's continue with the perl-style regular function preg_match_all.
? ? ? ? Function prototype:
?
preg_match_all ($pattern, $subject, array &$matches = null, $flags = null, $offset = null)
?
? ? ? ? Parameter: Identical to preg_match.
?
? ? ? ? Function: similar to preg_match, preg_match_all matches $ pattern in the $ subject string. Unlike preg_match, preg_match_all does not stop searching for the first matching result, search until the end of $ subject.
?
? ? ? ? Return value: according to the function, we can see that not only 0 or 1 is returned, preg_match_all searches for the entire $ subject until the end, and returns a few matching results. Let's look at an example with matching results.
?
$url = 'http://www.sina.com.cn/abc/de/fg.php?fff.html?id=1';$matches = array();$pattern = '/(\.){1}[^.|?]+(\?){1}/i';$count = preg_match_all($pattern, $url, $matches);var_dump($count);var_dump($matches);
? Output
int 2array (size=3) 0 => array (size=2) 0 => string '.php?' (length=5) 1 => string '.html?' (length=6) 1 => array (size=2) 0 => string '.' (length=1) 1 => string '.' (length=1) 2 => array (size=2) 0 => string '?' (length=1) 1 => string '?' (length=1)
? This example matches two results, which are http://www.sina.com.cn/abc/de/fg. Php?Fff. Html?Id = 1 the two red parts of the string. You will find that the elements in $ matches are also array types, $ matches [0] stores matching results, and $ matches [1] stores matching results of sub-regular 1, $ matches [2] stores the result of regular 2 matching. It may not be intuitive.
?
The Black Arrow is $ pattern regular match, and the Green Arrow is a child regular match.
Let's look at another example that does not match successfully.
$url = 'http://www.sina.com.cn/abc/de/fg.php?fff.html?id=1';$matches = array();$pattern = '/(\.){1}[^.|?]+(\?){2}/i';$count = preg_match_all($pattern, $url, $matches);var_dump($count);var_dump($matches);
? Output
int 0array (size=3) 0 => array (size=0) empty 1 => array (size=0) empty 2 => array (size=0) empty
?