1

Is there anyway to check count the number of characters for hebrew language.Following is the snippet

<?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
?>

Probably i should get the Hebrew count as '2' but not zero. Any solution ?

Smit Mehta
  • 196
  • 1
  • 10

1 Answers1

1

Try just splitting it by a space and counting the array length.

echo 'Hebrew Count :  '.count(explode(' ', html_entity_decode(mb_convert_encoding($h_str,'HTML-ENTITIES','UTF-8'),ENT_QUOTES,'UTF-8')));//prints 2
Scimonster
  • 32,893
  • 9
  • 77
  • 89