Update: I was looking at docs for strrpos thinking it was the docs for strpos. Sorry for the dumb mistake.
According to the docs, it says that when you provide a negative value as an offset argument, the function will start that many characters from the end of the string, searching backwards. It even shows this in Example #2. Why then can I not get this code to work properly?
$val = strpos('/imports/products/nin_avatar.png', '/', -2);
I am trying to get the index of the last forward slash in the string, yet it keeps returning false.. I’ve tried a couple different negative offsets, and none seem to work. Am I doing something wrong?
It seems it works as the OP intended now in a new version of PHP.
Historical answer
The PHP manual for
strpos()says…Source.
This would be more obvious if you developed with warnings enabled. In your development instance, use something like
error_reporting(E_ALL).