Don't think that is quite versitile enough.
What happens if it's "monkies in a tree"
Regex is far more powerful.
I did notice I should have tested mine before I handed it to him, it had a slight problem, but this can find any reference to a number of monkies for as many times as it appears anywhere...
<?
//you can combine pages...
$page = "There are 12 monkies hangin in the tree.\n";
$page .= "There are 42 monkies hangin in the tree.\n";
$page .= "There are 23 monkies hangin in the tree.\n";
//just run this one line of code...
preg_match_all('/([0-9]*[\s]+)\s+monkies+/i',$page,$numMonkies);
// $numMonkies[1] is now an array containing all the monkies by tree.
//and you can loop for nice output...
foreach($numMonkies[1] as $key=>$number) {
echo "$number damn monkies in dat tree!<br>";
$total += $number;
}
echo "<p>Lookie dere... Dere be a $total monkies in " . count(array_keys($numMonkies[1])) . " damn trees!</p>";
?>
Point is, regex can parse pages faster and more effeciently than a bunch or substr() functions chained together.
With one line of code I created a far more powerfull feature than your entire string parsing function.