还有检查希伯来语字符数的吗? language.Following是代码片段
<?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
?>也许我应该把希伯来语的计数定为“2”,而不是零。有解决办法吗?
发布于 2014-11-06 15:34:04
尝试将其拆分为一个空格并计数数组长度。
echo 'Hebrew Count : '.count(explode(' ', html_entity_decode(mb_convert_encoding($h_str,'HTML-ENTITIES','UTF-8'),ENT_QUOTES,'UTF-8')));//prints 2https://stackoverflow.com/questions/26732193
复制相似问题