Using str_word_count for UTF8 texts

前端 未结 2 1456
说谎
说谎 2020-12-07 01:10

I have this text:

$text  = \"Başka, küskün otomobil kaçtı buraya küskün otomobil neden kaçtı
          kaçtı buraya, oraya KISMEN @here #there J.J.Johanson h         


        
2条回答
  •  一生所求
    2020-12-07 01:30

    I think you're sort of on the right track with explode, but that doesn't handle regex.

    Change your code to:

    $namePattern = '/[\s,:?!]+/u';
    $wordsArray = preg_split($namePattern, $text, -1, PREG_SPLIT_NO_EMPTY);
    $wordsArray2 = array_count_values($wordsArray);
    arsort($wordsArray2);
    print_r($wordsArray2);
    

    Of course you may need to tweak the regex ($regexPattern) to meet your needs.

    Fiddle: http://ideone.com/JoIJqv

提交回复
热议问题