str_word_count() for non-latin words?

前端 未结 4 1150
我寻月下人不归
我寻月下人不归 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:24

    As it stated in str_word_count description

    'word' is defined as a locale dependent string

    Specify Bulgarian locale before calling str_word_count

    setlocale(LC_ALL, 'bg_BG');
    echo str_word_count($content);
    

    Read more about setlocale here.

提交回复
热议问题