Finding the nth match : preg_match_all « String « PHP
- PHP
- String
- preg_match_all
Finding the nth match
<?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";
}
?>
Related examples in the same category