2014-11-04 95 views
0

反正是有檢查計數的字符數爲希伯來語language.Following是片段PHP希伯來文字符數

<?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」,但不是零。 任何解決方案?

+0

http://stackoverflow.com/questions/8290537/is-php-str-word-count-multibyte-safe – 2014-11-04 10:09:50

+0

感謝@Hanky웃Panky – 2014-11-05 11:00:29

回答

1

嘗試將它分割一個空格並計算數組長度。

echo 'Hebrew Count : '.count(explode(' ', html_entity_decode(mb_convert_encoding($h_str,'HTML-ENTITIES','UTF-8'),ENT_QUOTES,'UTF-8')));//prints 2 
+0

雅這部作品,並帶來數更接近實際數量。對我來說感謝@Scimonster – 2014-11-10 05:21:46