PHP M Modifier: Match Anchored Pattern On Multiple Lines Of Text. – String Function

 
The anchor patterns ^ and $ match the beginning and end of an entire string by default. <?
$text = "name: Joe\noccupation: coder\n\n";
if ( preg_match_all( "/^\w+:\s+(.*)$/m", $text, $array ) ) {
  print "<pre>\n";
  print_r( $array );
  print "

\n”;
}
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.