note 110040 deleted from function.strpos by danbrown

From: Date: Thu, 13 Sep 2012 21:39:44 +0000
Subject: note 110040 deleted from function.strpos by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190729@lists.php.net to get a copy of this message
Note Submitter: lucien dot reb at gmail dot com ---- Thank for your code Paul-antoine, but we have a bug with this example : $test = "test"; var_dump(strpos_r($test, "test")); you have a while(0) with "while($seek = strrpos($haystack, $needle))" I edited your function to add the first position. function strpos_r($haystack, $needle) { if(strlen($needle) > strlen($haystack)) trigger_error(sprintf("%s: length of argument 2 must be <= argument 1", __FUNCTION__), E_USER_WARNING); $seeks = array(); while($seek = strrpos($haystack, $needle)) { array_push($seeks, $seek); $haystack = substr($haystack, 0, $seek); } if(substr_count($haystack,$needle) == 1) array_push($seeks, 0); return array_reverse($seeks); }

« previous php.notes (#190729) next »