the difference between 1.preg_match and Preg_match_all
The difference between Preg_match and Preg_match_all is that preg_match only matches once. and Preg_match_all all match until the end of the string. Cases:
String ' ABCDE ' (length=5)
Array (size=1)
0 =>
Array (size=3)
0 => string ' abcde ' (length=5)
1 => string ' ABCDE ' (length=5)
2 => string ' ABCDE ' (length=5)
*/
?>
2. The difference between greedy patterns and non-greedy patterns
such as: String str= "ABCAXC";
Patter p= "ab*c";
Greedy match: Regular expressions tend to match the maximum length, which is called greedy match. As above using pattern p to match the string str, the result is a match to: Abcaxc (ab*c).
Non-greedy match: just match to the result is good, fewer matching characters. As above using pattern p to match the string str, the result is a match to: ABC (AB*C).
Cases:
String ' http://www.baidu/.com?url=www.sina.com ' (length=38)
1 => string '//www.baidu/.com?url=www.sina. ' (length=30)
Array (size=2)
0 => string ' http://www.baidu/.com ' (length=21)
1 => string '//www.baidu/. ' (length=13)
* *
?>
the difference between the 3.preg_match_all parameter Preg_pattern_order (default) and Preg_set_order
-->]+> (. *)
-->]+>u ","Start:This is a test End", $out 1);
Var_dump ($out 1);
Echo (' Preg_set_order '); Preg_match_all ("<[^>]+> (. *)
-->]+>u ","Start:This is a test End", $out 2, Preg_set_order);
Var_dump ($out 2); /* Preg_pattern_order Array (size=2) 0 => Array (size=3) 0 => string 'Start:' (length=14) 1 => string 'This is a test' (length=21) 2 => string ' End' (length=10) 1 => Array (size=3) 0 => string ' Start: ' (length=7) 1 => string ' This is a test ' (length=14) 2 => string ' End ' (length=3) preg_set_order Array (size=3) 0 => Array (size=2) 0 =&G T String 'Start:' (length=14) 1 => string ' Start: ' (length=7) 1 => Array (size=2) 0 => string 'This is a test' (length=21) 1 => string ' This is a test ' (length=14) 2 => Array (size=2) 0 => string ' End' (length=10) 1 => string ' End ' (length=3) * *?>
Extended reading: Preg_match_all usages