如何统计textarea中的#words

I am wondering whether there is any javascript and PHP code to count number of words which are encoded in unicode.

Picked out from the php.net's manual

function str_word_count_utf8($str) {
  return count(preg_split('~[^\p{L}\p{N}\']+~u',$str));
}

As it is quoted

If the pattern contains utf-8, utf8_encode() the pattern, as it is expected to be valid utf-8 (using the u modifier).

str_word_count ( string $string [, int $format = 0 [, string $charlist ]] )

Counts the number of words inside string. If the optional format is not specified, then the return value will be an integer representing the number of words found. In the event the format is specified, the return value will be an array, content of which is dependent on the format.

look for details here