note 69172 added to function.strpos

From: Date: Fri, 25 Aug 2006 13:07:47 +0000
Subject: note 69172 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-116314@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 213.157.180.143 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- https://master.php.net/note/edit/69172 Del: integrated -- https://master.php.net/note/delete/69172/integrated Del: useless -- https://master.php.net/note/delete/69172/useless Del: bad code -- https://master.php.net/note/delete/69172/bad+code Del: spam -- https://master.php.net/note/delete/69172/spam Del: non-english -- https://master.php.net/note/delete/69172/non-english Del: in docs -- https://master.php.net/note/delete/69172/in+docs Del: other reasons-- https://master.php.net/note/delete/69172 Reject -- https://master.php.net/note/reject/69172 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116314) next »