Using the PHP Function mb_strpos
One of the most common tasks when working with strings is to find a substring within another string. Most programming languages have a built-in function for this task, but PHP doesn’t. However, there is a corresponding mb_strpos function in the mbstring extension.
mb_strpos is similar to strpos() in the sense that it finds the position of the first occurrence of a certain string in another one. However, it is multibyte safe and respects character boundaries in contrast to strpos(). It also supports multiple character encodings.
To use mb_strpos you need to have the mbstring extension installed, which is available through yum on Linux machines. mbstring provides a number of multibyte-specific string functions and handles character encoding conversion between the different encodings supported by PHP.
In addition to the mb_strpos function, the mbstring extension has other useful functions like mb_replace and mb_replace_with_char, which are similar to their counterparts in regular PHP, but work differently due to the fact that they handle multibyte encodings.
The mb_strpos function accepts the following parameters: $haystack = the main string, $needle = the string to be found in haystack and $offset = search offset. If the offset is not specified, 0 will be used. The mb_strpos() function can be called even with a negative offset, which means it will count from the end of the haystack string. The mb_strpos() returns the position of the first occurrence of needle in haystack, or FALSE.