: This article mainly introduces the regular expression PHP match and match_all. if you are interested in the PHP Tutorial, refer to it.
- Preg_match ($ pattern, $ subject, [array & match]) preg_match_all ($ pattern, $ subject, array & matches)
Preg match only matches once. the returned value is 0 or 1;
Preg match all matches multiple times and returns the number of times that match each time;
$ Pattern regular expression;
$ String or array to be matched by subject;
// Preg_match, preg_match_all $ pattern = '/[0-9]/'; $ subject = 'y1jp78yn16ww55 '; // define two empty arrays $ m1 = $ m2 = array (); $ t1 = preg_match ($ pattern, $ subject, $ m1 ); // $ m1 outputs a one-dimensional array. The return value is assigned to $ t1 $ t2 = preg_match_all ($ pattern, $ subject, $ m2 ); // $ m2 outputs a two-dimensional array. The return value is assigned to $ t2show ($ m1). // debug and output echo using the show function'
'; Show ($ m2); echo'
'; Show ($ t1.' | '. $ t2); // The number of matching times.
Preg_match can be matched at most once. the returned result is only 0 or the first matched element, in the form of an array.
Preg_match_all all match. The returned result may be 0 or all matched elements in the multi-dimensional array format.
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above describes the regular expression PHP article match and match_all, including some content, hope to be helpful to friends who are interested in PHP tutorials.