Home  >  Article  >  Backend Development  >  Troubleshooting PHP server returns Json problem_PHP tutorial

Troubleshooting PHP server returns Json problem_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:32:45875browse

We need to improve our programming ideas through continuous accumulation of experience, and use it flexibly characters. The problem is that the returned characters are GB2312, how to change them into UTF-8, and it is best to convert the entire array to UTF-8. After searching, the following code is found to solve the problem of PHP server returning Json:

function encodeUTF8($array)
  1. {
  2. foreach($array as $
  3. key= >$value) {
  4. if(!is_array($value) )
  5. {
  6. $array[$key]=mb_convert _encoding($value,"UTF-8","GBK ");

  7. }
  8. else
  9. {
  10. encodeUTF8($array[$key]);
  11. }
  12. } 🎜>return $array; 🎜>The above code is the specific solution to the problem of PHP server returning Json.
  13. http://www.bkjia.com/PHPjc/446105.html
  14. www.bkjia.com
  15. true
  16. http: //www.bkjia.com/PHPjc/446105.html
  17. TechArticle

We need to improve our programming ideas through continuous accumulation of experience. We can only know after reading the json_encode document after using it flexibly. , it can only encode UTF-8 characters. The problem is to return...

<ol class="dp-xml"><li class="alt"><span><span>echo '{"total":"'.$rscount.'<br>","results":'.json_encode<br>(encodeUTF8($result)).'}'; </span></span></li></ol>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn