Mega Code Archive

 
Categories / Php / Strings
 

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"; } ?>