note 12022 deleted from function.strpos by jimw

From: Date: Fri, 14 Dec 2001 20:05:46 +0000
Subject: note 12022 deleted from function.strpos by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22699@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; } ?>

« previous php.notes (#22699) next »