PHP Finding Nth Match – String Function

<?php
$todo = "1. a 2. B 3. C";preg_match_all("/\d\. ([^\d]+)/", $todo, $matches);print "The second item on the todo list is: ";print $matches[1][1];print "The entire todo list is: ";
foreach($matches[1] as $match) {
    print "$match\n";
}
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.