无论如何都要检查希伯来语的字符数。以下是片段
<?php
$e_str="This is football";// 3 words
$h_str="זה כדורגל";//hebrew translation of above
$h_str= trim(addslashes($h_str));
echo 'English Count : '.str_word_count(mb_convert_encoding($e_str, 'HTML-ENTITIES', 'ISO-8859-1')).'<br/>';//prints 3
echo 'Hebrew Count : '.str_word_count(html_entity_decode(mb_convert_encoding($h_str,'HTML-ENTITIES','UTF-8'),ENT_QUOTES,'UTF-8'));//prints zero
?>
可能我应该把希伯来语计算为&#39; 2&#39;但不是零。 任何解决方案?
答案 0 :(得分:1)
尝试用空格分割并计算数组长度。
echo 'Hebrew Count : '.count(explode(' ', html_entity_decode(mb_convert_encoding($h_str,'HTML-ENTITIES','UTF-8'),ENT_QUOTES,'UTF-8')));//prints 2