PHP preg_match Regular Expression function instance, Phppregmatch function
Regular expressions are used in almost all programming languages, and this example introduces the application of the Preg_match function of the normal expression in PHP.
The Preg_match () function is used to match a regular expression, successfully returning 1, otherwise returning 0.
Preg_match () will stop the match once the match is successful, and if you want to match all results, use the Preg_match_all () function.
Grammar:
| Preg_match (pattern, subject, matches) |
| Parameters |
Describe |
| Pattern |
Regular expressions |
| Subject |
Objects that need to be matched for retrieval |
| Matches |
Optional, storing an array of matching results |
Instance:
This instance matches a string with a. And a space followed by an uppercase letter and can only match to J. Because the Preg_match () match will stop the match once, and no longer match.
php$str= "Daniel J. Gross Catholic High School A. are a faith and family based community committed to developing CH Ristian leaders through educational excellence in the Marianist tradition. " ; if (preg_match("/[a-z"). /",$str,$matches)) { print_r($matches);}? >
Output Result:
Array
Original address: http://www.manongjc.com/article/52.html
Related reading:
PHP Regular Expression function usage instance
PHP preg_match functions and PHP Preg_match_al functions L instances, methods, examples
PHP Preg_match_all () function Use instance
PHP preg_match Regular Expression function instance
http://www.bkjia.com/PHPjc/1115243.html www.bkjia.com true http://www.bkjia.com/PHPjc/1115243.html techarticle PHP preg_match Regular Expression function instance, Phppregmatch function regular expression in almost all programming languages will be used, this example introduces the PHP expression Preg_match function should be ...