note 60037 added to function.strpos
| From: | dot) | Date: | Fri, 23 Dec 2005 15:44:45 +0000 |
| Subject: | note 60037 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100623@lists.php.net to get a copy of this message | ||
If you want to find positions of all needle's in haystack,
you can use this one:
while (($pos=strpos($haystack,$needle,$pos+1))!==false) $pos_array[$i++]=$pos;
But mind, that it will find from second char. You must use $pos=-1; before you want search from
first char.
{
$haystack="one two three one two three one two three one two three one";
$needle="one";
$pos=-1;
while (($pos=strpos($haystack,$needle,$pos+1))!==false) $pos_array[$i++]=$pos;
}
RESULT:
$pos_array[0] = 0
$pos_array[1] = 14
$pos_array[2] = 28
$pos_array[3] = 42
$pos_array[4] = 56
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60037
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60037&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60037&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60037&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60037&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60037&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60037&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60037&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60037&report=yes
Search -- http://master.php.net/manage/user-notes.php