note 108425 deleted from function.stripos by danbrown

From: Date: Thu, 10 May 2012 17:00:39 +0000
Subject: note 108425 deleted from function.stripos by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187632@lists.php.net to get a copy of this message
Note Submitter: mtroy dot student at gmail dot com ---- when you want to know how much of substring occurrences, you'll use "substr_count". But, retrieve their positions, will be harder. So, you can do it by starting with the last occurrence : function stripos_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 = strripos($haystack, $needle)) { array_push($seeks, $seek); $haystack = substr($haystack, 0, $seek); } return $seeks; } it will return an array of all occurrences a the substring in the string Example : $test = "this is a test for testing a test function... blah blah"; var_dump(stripos_r($test, "test")); // output array(3) { [0]=> int(29) [1]=> int(19) [2]=> int(10) } Paul-antoine.

« previous php.notes (#187632) next »