note 55670 added to function.strrpos
| From: | fab at osu1 dot php dot net | Date: | Wed, 10 Aug 2005 11:07:06 +0000 |
| Subject: | note 55670 added to function.strrpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93361@lists.php.net to get a copy of this message | ||
RE: hao2lian
There are a lot of alternative - and unfortunately buggy - implementations of strrpos() (or
last_index_of as it was called) on this page. This one is a slight modifiaction of the one below,
but it should world like a *real* strrpos(), because it returns false if there is no needle in the
haystack.
<?php
function my_strrpos($haystack, $needle) {
$index = strpos(strrev($haystack), strrev($needle));
if($index === false) {
return false;
}
$index = strlen($haystack) - strlen($needle) - $index;
return $index;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.strrpos.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55670
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55670&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55670&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55670&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55670&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55670&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55670&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55670&report=yes
Search -- http://master.php.net/manage/user-notes.php