preg_match_all print *all* matches

后端 未结 3 1498
情话喂你
情话喂你 2021-01-15 03:33

I need to print all matches using preg_match_all.

$search = preg_match_all($pattern, $string, $matches);

foreach ($matches as $match) {
    echo $match[0];
         


        
3条回答
  •  悲哀的现实
    2021-01-15 03:52

    You could loop recursively. This example requires SPL and PHP 5.1+ via RecursiveArrayIterator:

    foreach( new RecursiveArrayIterator( $matches ) as $match )
        print $match;
    

提交回复
热议问题