Regular expressions are used in almost all programming languages. This example introduces the application of the regular expression preg_match function in php .
The preg_match() function is used for regular expression matching and returns 1 successfully, otherwise it returns 0.
preg_match() will stop matching after one successful match. If you want to match all results, you need to use the preg_match_all() function.
Grammar:
preg_match (pattern , subject, matches) |
|
Description |
||||||||
pattern | Regular expression | ||||||||
subject | Need to match the retrieved object | ||||||||
matches | Optional, array to store matching results |
<?<span>php </span><span>$str</span>="Daniel J. Gross Catholic High School A. is a faith and family based community committed to developing Christian leaders through educational excellence in the Marianist tradition."<span>; </span><span>if</span>(<span>preg_match</span>("/[A-Z]. /",<span>$str</span>,<span>$matches</span><span>)){ </span><span>print_r</span>(<span>$matches</span><span>); } </span>?>
<span>Array</span> ( [0] => J. )
Output result:
Original address: http://www.manongjc.com/article/52.html
Related reading:
PHP regular expression function usage examples
php preg_match function and php preg_match_al function l instances, methods, examples
php preg_match_all() function usage example
php preg_match regular expression function example
php preg_match regular expression function example, phppregmatch function regular expressions are used in almost all programming languages, this book An example introduces the application of the regular expression preg_match function in php...