note 69172 deleted from function.strpos by danbrown

From: Date: Sun, 17 May 2009 16:34:21 +0000
Subject: note 69172 deleted from function.strpos by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154850@lists.php.net to get a copy of this message
Note Submitter: banana dot meal at gmail dot com ---- To thepsion5 at hotmail dot com: Please mind the warning part of the documentation! Your function won't work on $Haystack s starting with $needle. Here's a solution for that: <? function findAllOccurences($Haystack, $needle, $limit=0) { $Positions = array(); $currentOffset = 0; $count=0; while(($pos = strpos($Haystack, $needle, $offset))!==false && ($count < $limit || $limit == 0)) { $Positions[] = $pos; $offset = $pos + strlen($needle); $count++; } return $Positions; } ?>

« previous php.notes (#154850) next »