$string = "01234567890*****12345678901234567890*";
echo strrpos($string,'*****');
why does this return 36 and not 15? (click here to test)
from php.net
strrpos — Find the position of the last occurrence of a substring in a string
What am I missing out on???
Thank you!
SOLUTION: using the answers bellow, I provided a PHP4 alternative
$haystack = "01234567890*****12345678901234567890*";
$needle = '*****';
$position = strlen($haystack) - strlen($needle) - strpos(strrev($haystack),strrev($needle));
echo $position; // 11
The strrpos() function finds the position of the last occurrence of a string inside another string. Note: The strrpos() function is case-sensitive. Related functions: strpos() - Finds the position of the first occurrence of a string inside another string (case-sensitive)
strrchr() — Locate Last Occurrence of Character in String The strrchr() function finds the last occurrence of c (converted to a character) in string . The ending null character is considered part of the string . The strrchr() function returns a pointer to the last occurrence of c in string .
Probably you're using PHP 4:
from php.net
needle: If needle is not a string, it is converted to an integer and applied as the ordinal value of a character. The needle can only be a single character in PHP 4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With