PHP: Problems finding the most frequent character in a UTF-8 string (eg 唐犬土用家犬尨犬山桑)?

请求翻译

From an MySQL database I can extract the following utf-8 characters:

"唐犬土用家犬尨犬山桑山犬巴戦师子幻日幻月引纲忠犬爱犬戌年成犬教条教义"

I am trying to find the most frequent character in this string. I tried putting each as element into an array $arr and do array_count_values($arr); Unfortunately the array operations (or is print_r the culprit?) produce mis-encoded output like this: [0] => ? [1] => ? [2] => ? [3] => ? I can display the characters fine in other situations (i.e. retrieving from MySQL and displaying the characters within php works OKAY!), but the array functions (or array output) seem to mess things up.

I HAVE changed /etc/php5/apache2/php.ini
and put default_charset = "utf-8" in there.

(And I HAVE SET NAMES ... etc)

A) Where is the problem? B) Could I do the job without resorting to arrays altogether (i.e. just using string function)?

Thanks for your help.

1个回答