note 87061 added to function.strpos
| From: | Tim at osu1 dot php dot net | Date: | Tue, 18 Nov 2008 01:52:32 +0000 |
| Subject: | note 87061 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146634@lists.php.net to get a copy of this message | ||
If you would like to find all occurences of a needle inside a haystack you could use this function
strposall($haystack,$needle);. It will return an array with all the strpos's.
/**
* strposall
*
* Find all occurrences of a needle in a haystack
*
* @param string $haystack
* @param string $needle
* @return array or false
*/
function strposall($haystack,$needle){
$s=0;
$i=0;
while (is_integer($i)){
$i = strpos($haystack,$needle,$s);
if (is_integer($i)) {
$aStrPos[] = $i;
$s = $i+strlen($needle);
}
}
if (isset($aStrPos)) {
return $aStrPos;
}
else {
return false;
}
}
----
Server IP: 89.248.170.61
Probable Submitter: 84.245.2.186
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- https://master.php.net/note/edit/87061
Del: integrated -- https://master.php.net/note/delete/87061/integrated
Del: useless -- https://master.php.net/note/delete/87061/useless
Del: bad code -- https://master.php.net/note/delete/87061/bad+code
Del: spam -- https://master.php.net/note/delete/87061/spam
Del: non-english -- https://master.php.net/note/delete/87061/non-english
Del: in docs -- https://master.php.net/note/delete/87061/in+docs
Del: other reasons-- https://master.php.net/note/delete/87061
Reject -- https://master.php.net/note/reject/87061
Search -- https://master.php.net/manage/user-notes.php