str_word_count() for non-latin words?

You may do it with regex:

$str = "текст на кирилица";
echo 'Number of words: '.count(preg_split('/\s+/', $str));

here I'm defining word delimiter as space characters. If there may be something else that will be treated as word delimiter, you'll need to add it into your regex.

Also, note, that since there's no utf characters in regex (not in string) - /u modifier isn't required. But if you'll want some utf characters to act as delimiter, you'll need to add this regex modifier.

Update:

If you want only cyrillic letters to be treated in words, you may use:

$str = "текст 
на 12453
кирилица";
echo 'Number of words: '.count(preg_split('/[^А-Яа-яЁё]+/u', $str));

Tags:

Php

Count