note 92849 added to function.strpos
| From: | ah dot d at hotmail dot com | Date: | Tue, 11 Aug 2009 20:29:19 +0000 |
| Subject: | note 92849 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-159343@lists.php.net to get a copy of this message | ||
A strpos modification to return an array of all the positions of a needle in the haystack
function strallpos($haystack,$needle,$offset = 0){
$result = array();
for($i = $offset; $i<strlen($haystack); $i++){
$pos = strpos($haystack,$needle,$i);
if($pos !== FALSE){
$offset = $pos;
if($offset >= $i){
$i = $offset;
$result[] = $offset;
}
}
}
return $result;
}
example:-
$haystack = "ASD is trying to get out of the ASDs cube but the other ASDs told him that his
behavior will destroy the ASDs world";
$needle = "ASD";
print_r(strallpos($haystack,$needle));
//getting all the positions starting from a specified position
print_r(strallpos($haystack,$needle,34));
----
Server IP: 69.147.83.197
Probable Submitter: 41.233.45.186
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- https://master.php.net/note/edit/92849
Del: integrated -- https://master.php.net/note/delete/92849/integrated
Del: useless -- https://master.php.net/note/delete/92849/useless
Del: bad code -- https://master.php.net/note/delete/92849/bad+code
Del: spam -- https://master.php.net/note/delete/92849/spam
Del: non-english -- https://master.php.net/note/delete/92849/non-english
Del: in docs -- https://master.php.net/note/delete/92849/in+docs
Del: other reasons-- https://master.php.net/note/delete/92849
Reject -- https://master.php.net/note/reject/92849
Search -- https://master.php.net/manage/user-notes.php