str_word_count() for non-latin words?

前端 未结 4 1122
我寻月下人不归
我寻月下人不归 2021-01-05 14:12

im trying to count the number of words in variable written in non-latin language (Bulgarian). But it seems that str_word_count() is not counting non-latin words. The encodin

4条回答
  •  抹茶落季
    2021-01-05 14:33

    The best solution I found is to provide a list of characters for word count function:

    $text = 'текст на кирилице and on english too';
    $count = str_word_count($text, 0, 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя');
    echo $count; // => 7
    

提交回复
热议问题