多語的版本:
$encoding = mb_detect_encoding($text);
$result = array(
'count_cn' => 0,
'count_en' => 0,
'count_jp' => 0,
'count_es' => 0,
'count_id' => 0,
'count_ko' => 0,
);
$text_cn = preg_replace("/[^\p{Han}\?\!\;\.\〜\ー\。\,\「\」\《\、\》\【\】\『\』\:\(\)\(\)\/\・]/u","", $text);
$result['count_cn'] = mb_strlen($text_cn, $encoding);
$text_en = preg_replace("/[\'\"]/","", $text);
$text_en = preg_replace("/[^a-zA-Z\s]/"," ", $text_en);
$result['count_en'] = str_word_count($text_en);
$text_cyrillic = preg_replace("/[^\p{Cyrillic}\s]/","", $text);
$result['count_ru'] = str_word_count($text_cyrillic);
//$pattern_jp = "[^\p{Hiragana}\p{Katakana}\]";
$text_jp = preg_replace("/[^\p{Han}\p{Hiragana}\p{Katakana}\.\〜\ー\。\,\「\」\《\、\》\【\】\『\』\:\(\)\(\)\/\・]/u","", $text );
//$this->count_jp = mb_strlen($text_jp, $encoding);
$result['count_jp'] = mb_strlen($text_jp, $encoding);
$text_ko = preg_replace("/[^\p{Han}\p{Hangul}\?\!\;\.\〜\ー\。\,\「\」\《\、\》\【\】\『\』\:\(\)\(\)\/\・]/u","", $text);
$result['count_ko'] = mb_strlen($text_ko, $encoding);
$text_ru = preg_replace("/[^\x{0430}-\x{044F}\x{0410}-\x{042F}\s]/u"," ", $text);
$result['count_ru'] = count(preg_split('/\s+/', $text_ru));
$result['count_ru_literra'] = $result['count_ru'];
$result['count_es'] = str_word_count($text_en);
$result['count_id'] = str_word_count($text_en);
return $result;
多語的版本: