Use of preg regular function in PHP
the difference between 1.preg_match and Preg_match_all
The difference between Preg_match and Preg_match_all is that preg_match matches only once. The 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 and non-greedy modes
such as: String str= "ABCAXC";
Patter p= "Ab*c";
Greedy matching: Regular expressions tend to match the maximum length, which is called greedy matching. As above using pattern p to match string str, the result is matched to: Abcaxc (ab*c).
Non-greedy match: just match to the result is good, fewer matching characters. As above using pattern p to match string str, the result is matched 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) */?>
3.preg_match_all parameter Preg_pattern_order (default) and Preg_set_order differences
]+> (. *)
]+>| U ","Start:This is a testEnd", $out 1); Var_dump ($out 1); Echo (' Preg_set_order ');p reg_match_all (" |<[^>]+> (. *)
]+>| U ","Start:This is a testEnd", $out 2, Preg_set_order); Var_dump ($out 2);/*preg_pattern_orderarray (size=2) 0 = array (size=3) 0 = St Ring '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 ' (le NGTH=14) 2 = String ' End ' (length=3) preg_set_orderarray (size=3) 0 = = Array (size=2) 0 = 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) */?>
Read MORE: Preg_match_all usage examples
http://www.bkjia.com/PHPjc/894184.html www.bkjia.com true http://www.bkjia.com/PHPjc/894184.html techarticle The difference between the preg regular function in PHP using 1.preg_match and Preg_match_all Preg_match and Preg_match_all differences is preg_match match only once. And the Preg_match_all all match until the string knot ...