PHP Function MB_Substr_Count
Article about php function mb_substr_count
A multibyte string extension for PHP. The mbstring extension provides support for Simplified Chinese, Traditional Chinese, Korean, Russian, and Japanese language strings in PHP's string data type, and allows for operations that manipulate these strings with multibyte support. The mbstring extension can be enabled in the configure script using --enable-mbstring=LANG.
The mb_substr_count() function counts the number of times a needle substring occurs in a haystack string. It takes three parameters: haystack, needle and encoding. encoding specifies the character encoding for needle and haystack; if it is absent or null, the internal character encoding will be used.
mb_substr_count uses a recursive search to find occurrences of the needle in the haystack string, and returns a count of the number of times it was found. This method is significantly slower than the string datatype's built-in substr() function, as it requires recursive searches of a logarithmic length of the haystack string, for every possible start and end point of the needle. Moreover, the recursive search method is not accurate and will often return false. mb_substr_count is not the best choice for performance-critical applications. A more efficient alternative would be to split the text into an array of letters and then iterate over it.