function mb_substr_count($haystack, $needle, $encoding = '') { global $mbemu_internals; $encoding = mb_detect_encoding($haystack, $encoding); switch ($e = $mbemu_internals['encoding'][$encoding]) { case 0: //ascii //ascii case 1: //euc-jp //euc-jp case 2: //shift-jis //shift-jis case 4: //utf-8 //utf-8 case 5: //utf-16 //utf-16 case 6: //iso-8859-1 preg_match_all('/' . $mbemu_internals['regex'][$e] . '/', $haystack, $ar_h); preg_match_all('/' . $mbemu_internals['regex'][$e] . '/', $needle, $ar_n); return _sub_substr_count($ar_h[0], $ar_n[0]); case 3: //jis $haystack = mb_convert_encoding($haystack, 'SJIS', 'JIS'); $needle = mb_convert_encoding($needle, 'SJIS', 'JIS'); preg_match_all('/' . $mbemu_internals['regex'][2] . '/', $haystack, $ar_h); preg_match_all('/' . $mbemu_internals['regex'][2] . '/', $needle, $ar_n); return _sub_substr_count($ar_h[0], $ar_n[0]); } }
function mb_substr_count($haystack, $needle, $encoding = '') { global $_mb_encoding, $euc_match, $utf8_match, $sjis_match; $encoding = _get_encoding($haystack, $encoding); switch ($_mb_encoding[$encoding]) { case 1: //euc-jp preg_match_all("/{$euc_match}/", $haystack, $ar_h); preg_match_all("/{$euc_match}/", $needle, $ar_n); return _sub_substr_count($ar_h[0], $ar_n[0]); case 0: //ascii //ascii case 4: //utf-8 preg_match_all("/{$utf8_match}/", $haystack, $ar_h); preg_match_all("/{$utf8_match}/", $needle, $ar_n); return _sub_substr_count($ar_h[0], $ar_n[0]); case 2: //shift-jis preg_match_all("/{$sjis_match}/", $haystack, $ar_h); preg_match_all("/{$sjis_match}/", $needle, $ar_n); return _sub_substr_count($ar_h[0], $ar_n[0]); case 3: //jis $haystack = mb_convert_encoding($haystack, 'SJIS', 'JIS'); $needle = mb_convert_encoding($needle, 'SJIS', 'JIS'); preg_match_all("/{$sjis_match}/", $haystack, $ar_h); preg_match_all("/{$sjis_match}/", $needle, $ar_n); return _sub_substr_count($ar_h[0], $ar_n[0]); } }