Search code examples
phpstrpos

How to get position of last character in a string?


For example, I have $string = "abc+def", how can i get position of 'f'? Is it possible of finding position of last character in the string, in the above example, 'f' is last character.


Solution

  • In PHP, as in most languages with zero-based indexing, the index of the last character in a string will be one less than the length of the string (strlen($string) - 1).