note 72345 deleted from function.strrpos by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 15:00:05 +0000 |
| Subject: | note 72345 deleted from function.strrpos by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197290@lists.php.net to get a copy of this message | ||
Note Submitter: Guilherme Garnier
----
Actually, there is a little problem on your code: if $needle is not found inside $haystack, the
function should return FALSE, but it is actually returning strlen($haystack) - strlen($needle). Here
is a corrected version of it:
<?php
function stringrpos($haystack,$needle,$offset=NULL)
{
if (strpos($haystack,$needle,$offset) === FALSE)
return FALSE;
return strlen($haystack)
- strpos( strrev($haystack) , strrev($needle) , $offset)
- strlen($needle);
}
?>