note 78868 deleted from function.strpos by danbrown
| From: | danbrown@php.net | Date: | Wed, 03 Aug 2011 13:16:58 +0000 |
| Subject: | note 78868 deleted from function.strpos by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-182162@lists.php.net to get a copy of this message | ||
Note Submitter: giulioNOSPAM at iunknown dot org
----
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);
}
?>