note 39917 deleted from function.strpos by tularis

From: Date: Wed, 22 Aug 2007 13:28:05 +0000
Subject: note 39917 deleted from function.strpos by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-129704@lists.php.net to get a copy of this message
Note Submitter: nanobot2k at nanobot2k dot org ---- 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; } ?>

« previous php.notes (#129704) next »