note 39917 added to function.strpos
| From: | nanobot2k at nanobot2k dot org | Date: | Sun, 15 Feb 2004 18:45:07 +0000 |
| Subject: | note 39917 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-65176@lists.php.net to get a copy of this message | ||
This function will return the number of times a needle is found in a haystack...if none that it will
return 0.
Cheers to lgbr for saving me the headache! :P
<?php
/**
* @return int
* @param string $haystack
* @param string $needle
* @desc returns the number of times a needle is found in a haystack, 0 if none found
*/
function totalStr($haystack, $needle,$i = 0)
{
while(strpos($haystack,$needle) !== false) {
$haystack = substr($haystack, (strpos($haystack,$needle) + 1));
$i++;
}
return $i;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39917
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39917&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39917&report=yes
Search -- http://master.php.net/manage/user-notes.php