note 110040 added to function.strpos

From: Date: Thu, 13 Sep 2012 21:36:47 +0000
Subject: note 110040 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-190728@lists.php.net to get a copy of this message
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); } ---- Server IP: 69.147.83.197 Probable Submitter: 90.6.175.59 ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- https://master.php.net/note/edit/110040 Del: integrated -- https://master.php.net/note/delete/110040/integrated Del: useless -- https://master.php.net/note/delete/110040/useless Del: bad code -- https://master.php.net/note/delete/110040/bad+code Del: spam -- https://master.php.net/note/delete/110040/spam Del: non-english -- https://master.php.net/note/delete/110040/non-english Del: in docs -- https://master.php.net/note/delete/110040/in+docs Del: other reasons-- https://master.php.net/note/delete/110040 Reject -- https://master.php.net/note/reject/110040 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#190728) next »