Using the PHP Function mb_strrpos()
When working with strings, one of the common tasks is to check whether a given string is a part (substring) of another string. Most programming languages have a built-in function for this purpose. For example, in Java, you can use the startsWith() function. Unfortunately, there is no such function in PHP. So, we imitate this functionality using a mb_strrpos() function.
mb_strrpos() is a function that finds the position of the last occurrence of a string in the given haystack string. The function performs a multibyte safe strrpos() operation based on the number of characters. Therefore, the needle position is counted from the beginning of the haystack string. The first character's position is 0, and the second is 1. The mb_strrpos() accepts three parameters:
The haystack is the main string that you want to check for the needle. The needle is the string that you want to find in the haystack. The offset is the position in the haystack where you want to start searching for the needle. If the offset is a negative value, then it will search from the end of the haystack. The mb_strrpos() also accepts an encoding parameter. If you omit this parameter, then the internal character encoding is used.
Note that this function is case-sensitive. If you need a case-insensitive version, then you can consider a str_icontains() function.