Questions about Chinese sorting

Source: Internet
Author: User
My data source is in utf8 format, but I want to sort the data. because it is Chinese, I convert it to gbk or gbk2312, however, the sorting is partially inaccurate. I am using the array_multi_sort method of php to sort the results. in the black box, the data is very...

My data source is in utf8 format, but I want to sort the data. because it is Chinese, I want to convert it to gbk or gbk2312, but the sorting is partially inaccurate.

I used the php array_multi_sort method for sorting.

This problem occurs in Sorting results.

The data in the black box is obviously incorrectly arranged in descending order of pinyin, but the subsequent data is suitable. why? Or is the gbk Library incomplete?

Add a test code

$ Array = array ("Heron", "hao", "Han", "Hua", "Zhong", "Yi", "Cui", "Zhong ", "Kai", "Xin"); foreach ($ array as $ val) {$ newArr [] = iconv ('utf8', 'gbk', $ val );} array_multisort ($ newArr, SORT_DESC, SORT_FLAG_CASE); echo"
";print_r($newArr);die;

Reply content:

My data source is in utf8 format, but I want to sort the data. because it is Chinese, I want to convert it to gbk or gbk2312, but the sorting is partially inaccurate.

I used the php array_multi_sort method for sorting.

This problem occurs in Sorting results.

The data in the black box is obviously incorrectly arranged in descending order of pinyin, but the subsequent data is suitable. why? Or is the gbk Library incomplete?

Add a test code

$ Array = array ("Heron", "hao", "Han", "Hua", "Zhong", "Yi", "Cui", "Zhong ", "Kai", "Xin"); foreach ($ array as $ val) {$ newArr [] = iconv ('utf8', 'gbk', $ val );} array_multisort ($ newArr, SORT_DESC, SORT_FLAG_CASE); echo"
";print_r($newArr);die;

If the sorting results by Chinese characters are not necessarily accurateasciiSorting, but the complexity of the program increases. if your classified data is read from the database, try to add it to the database.Sorting field

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.