To find the last index of a character in a string in PHP, you can use the strrpos()
function. This function returns the position of the last occurrence of a substring in a string. Here's an example:
main.php96 chars4 lines
In this example, we're searching for the last occurrence of the comma "," in the string "Hello, world!". The strrpos()
function returns the index of the last comma, which is 5.
If the character is not found in the string, strrpos()
returns false
.
gistlibby LogSnag