note 80008 added to function.strrpos
| From: | dixonmd at gmail dot com | Date: | Mon, 24 Dec 2007 10:42:15 +0000 |
| Subject: | note 80008 added to function.strrpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-133967@lists.php.net to get a copy of this message | ||
<php
$pos = strlen(string $haystack) - strpos (strrev(string $haystack), strrev(string $needle)) -
strlen(string $needle);
?>
If in the needle there is more than one character then in php 4 we can use the above statement
for finding the position of last occurrence of a substring in a string instead of strrpos. Because
in php 4 strrpos uses the first character of the substring.
eg :
<php
$haystack = "you you you you you";
$needle = "you";
$pos1 = strlen($haystack) - strpos (strrev($haystack), strrev($needle)) - strlen($needle);
echo $pos1 . "<br>";
$pos2 strrpos($haystack, $needle);
echo $pos2 . "<br>";
?>
----
Server IP: 203.199.124.111
Probable Submitter: 220.224.228.67
----
Manual Page -- http://www.php.net/manual/en/function.strrpos.php
Edit -- https://master.php.net/note/edit/80008
Del: integrated -- https://master.php.net/note/delete/80008/integrated
Del: useless -- https://master.php.net/note/delete/80008/useless
Del: bad code -- https://master.php.net/note/delete/80008/bad+code
Del: spam -- https://master.php.net/note/delete/80008/spam
Del: non-english -- https://master.php.net/note/delete/80008/non-english
Del: in docs -- https://master.php.net/note/delete/80008/in+docs
Del: other reasons-- https://master.php.net/note/delete/80008
Reject -- https://master.php.net/note/reject/80008
Search -- https://master.php.net/manage/user-notes.php