note 12022 added to function.strpos.php
| From: | clambert at gamespy dot com | Date: | Mon, 19 Mar 2001 05:21:10 +0000 |
| Subject: | note 12022 added to function.strpos.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-12536@lists.php.net to get a copy of this message | ||
The above won't work as expected. If $needle is "aba" and $haystack is
"abababaaaababa" then it'll return 5, even though it should return 2.
Try this:
<?
function str_num ($haystack, $needle) {
$needle_len = strlen($needle);
while (1) {
$pos = strpos($haystack, $needle, $pos) + $needle_len;
if ($pos == $needle_len && $i)
break;
$i++;
}
return $i;
}
?>
http://www.php.net/manual/en/function.strpos.php