note 68692 deleted from function.strpos by danbrown

From: Date: Sun, 17 May 2009 16:34:44 +0000
Subject: note 68692 deleted from function.strpos by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154852@lists.php.net to get a copy of this message
Note Submitter: thepsion5 at hotmail dot com ---- I created this little function based on the one posted by chasesan at gmail dot com; It find all occurences of a string within another string and returns their positions as an array: <?PHP function findAllOccurences($Haystack, $needle, $limit=0) { $Positions = array(); $currentOffset = 0; $count=0; while(($pos = strpos($Haystack, $needle, $offset)) && ($count < $limit || $limit == 0)) { $Positions[] = $pos; $offset = $pos + strlen($needle); $count++; } return $Positions; } ?> I hope this helps someone :)

« previous php.notes (#154852) next »