note 80008 modified in function.strrpos by tularis
| From: | tularis@php.net | Date: | Tue, 10 Jan 2012 21:00:20 +0000 |
| Subject: | note 80008 modified in function.strrpos by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-185557@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>";
?>
--was--
<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>";
?>
http://php.net/manual/en/function.strrpos.php