note 17261 added to function.strpos
| From: | admin at puremedia dot ca | Date: | Sun, 02 Dec 2001 10:44:19 +0000 |
| Subject: | note 17261 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-21526@lists.php.net to get a copy of this message | ||
To: clambert@gamespy.com
After trying your routine, I realised that it wouldn't work either. First of all, it
doesn't take into account the particularities of strpos and will return "1"
regardless of wherther or not the string was found. Plus, if your needle is larger than the
haystack, you will get an offset error.
This one is tested, try it if you like. ($input like $needle, $search like $haystack)
function find_string ($input, $search)
{
while (is_integer(strpos($search,$input,$offset))) {
$offset+=strlen($input);
$found++;}
return $found;
}
----------
Mickael Nadeau, President
Pure Media Productions
(418) 527-2155
----------
admin@puremedia.ca
http://www.puremedia.ca/
----------
--
http://www.php.net/manual/en/function.strpos.php
http://master.php.net/manage/user-notes.php?action=edit+17261
http://master.php.net/manage/user-notes.php?action=delete+17261
http://master.php.net/manage/user-notes.php?action=reject+17261