preg_match_all

PHP 4, PHP 5, PHP 7, PHP 8
preg_match_all - Perform a global regular expression match

Example #1 Find matching HTML tags (greedy)

Result: matched: <b>bold text</b> part 1: <b> part 2: b part 3: bold text part 4: </b> matched: <a href=howdy.html>click me</a> part 1: <a href=howdy.html> part 2: a part 3: click me part 4: </a>
PHP Version:

Example #2 Using named subpattern

Result: Array ( [0] => Array ( [0] => a: 1 [1] => b: 2 [2] => c: 3 ) [name] => Array ( [0] => a [1] => b [2] => c ) [1] => Array ( [0] => a [1] => b [2] => c ) [digit] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [2] => Array ( [0] => 1 [1] => 2 [2] => 3 ) )
PHP Version:

Example #3 Getting all phone numbers out of some text.

PHP Version:


Example #4 of preg_match_all

PHP Version:


Function preg_match_all:

Regular Expressions (Perl-Compatible) Functions

Most used PHP functions