Troubleshooting PHP Server Return JSON problem _php tutorial

Source: Internet
Author: User
We need to improve our programming ideas and apply them flexibly in the continuous experience accumulation.

Later read Json_encode's document only to know that it can only encode UTF-8 characters. The problem is that the returned character is GB2312, how it becomes UTF-8, and it is best to convert the entire array UTF-8. After the search has the following code to resolve the PHP service side return JSON problem:

    1. function EncodeUTF8 ($array)
    2. {
    3. foreach ($array as $key=>$value)
    4. {
    5. if (!is_array ($value))
    6. {
    7. $array [$key]=mb_convert
      _encoding ($value, "UTF-8", "GBK");
    8. }
    9. Else
    10. {
    11. EncodeUTF8 ($array [$key]);
    12. }
    13. }
    14. return $array;
    15. }

Each time the result is returned:

 
  
  1. Echo ' {"Total": "'. $rscount. '
    "," Results ": '. Json_encode

The above code is a concrete solution to the JSON problem returned by the PHP server.


http://www.bkjia.com/PHPjc/446105.html www.bkjia.com true http://www.bkjia.com/PHPjc/446105.html techarticle we need to improve our programming thinking in the continuous accumulation of experience, flexible use later to see Json_encode documents only know, it can only encode UTF-8 characters. The problem is to return ...

  • 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.