note 68692 added to function.strpos
| From: | thepsion5athotmaildotcom at osu1 dot php dot net | Date: | Mon, 07 Aug 2006 17:57:17 +0000 |
| Subject: | note 68692 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115613@lists.php.net to get a copy of this message | ||
I created this little function based on the one posted by chasesan at gmail dot com; It find all
occurences of a string within another string and returns their positions as an array:
<?PHP
function findAllOccurences($Haystack, $needle, $limit=0)
{
$Positions = array();
$currentOffset = 0;
$count=0;
while(($pos = strpos($Haystack, $needle, $offset)) && ($count < $limit || $limit == 0))
{
$Positions[] = $pos;
$offset = $pos + strlen($needle);
$count++;
}
return $Positions;
}
?>
I hope this helps someone :)
----
Server IP: 64.71.164.2
Probable Submitter: 12.145.48.90
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- https://master.php.net/note/edit/68692
Del: integrated -- https://master.php.net/note/delete/68692/integrated
Del: useless -- https://master.php.net/note/delete/68692/useless
Del: bad code -- https://master.php.net/note/delete/68692/bad+code
Del: spam -- https://master.php.net/note/delete/68692/spam
Del: non-english -- https://master.php.net/note/delete/68692/non-english
Del: in docs -- https://master.php.net/note/delete/68692/in+docs
Del: other reasons-- https://master.php.net/note/delete/68692
Reject -- https://master.php.net/note/reject/68692
Search -- https://master.php.net/manage/user-notes.php