note 78868 added to function.strpos
| From: | giulioNOSPAMatiunknowndotorg at osu1 dot php dot net | Date: | Wed, 31 Oct 2007 10:19:18 +0000 |
| Subject: | note 78868 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-131854@lists.php.net to get a copy of this message | ||
A further implementation of the great rstrpos function posted in this page. Missing some parameters
controls, but the core seems correct.
<?php
// Parameters:
//
// haystack : target string
// needle : string to search
// offset : which character in haystack to start searching, FROM THE END OF haystack
// iNumOccurrence : how many needle to search into haystack beginning from offset ( i.e. the 4th
occurrence of xxx into yyy )
function rstrpos ($haystack, $needle, $offset=0, $iNumOccurrence=1)
{
//
$size = strlen ($haystack);
$iFrom = $offset;
$iLoop = 0;
//
do
{
$pos = strpos (strrev($haystack), strrev($needle), $iFrom);
$iFrom = $pos + strlen($needle);
}
while ((++$iLoop)<$iNumOccurrence);
//
if($pos === false) return false;
//
return $size - $pos - strlen($needle);
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 87.16.235.186
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- https://master.php.net/note/edit/78868
Del: integrated -- https://master.php.net/note/delete/78868/integrated
Del: useless -- https://master.php.net/note/delete/78868/useless
Del: bad code -- https://master.php.net/note/delete/78868/bad+code
Del: spam -- https://master.php.net/note/delete/78868/spam
Del: non-english -- https://master.php.net/note/delete/78868/non-english
Del: in docs -- https://master.php.net/note/delete/78868/in+docs
Del: other reasons-- https://master.php.net/note/delete/78868
Reject -- https://master.php.net/note/reject/78868
Search -- https://master.php.net/manage/user-notes.php