Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What if php ajax gets the Chinese garbled code?

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the php ajax access to Chinese garbled code how to do, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

1. Execute the "iconv ('utf-8','gb2312',$_POST [' Data'])" code.

2. Read Chinese characters from the database through PHP and convert them to json format.

Function arrayRecursive (& $array, $function, $apply_to_keys_also = false) {static $recursive_counter = 0; if (+ + $recursive_counter > 1000) {die ('possible deep recursion attack');} foreach ($array as $key = > $value) {if (is_array ($value)) {arrayRecursive ($array [$key], $function, $apply_to_keys_also) } else {$array [$key] = $function ($value);} if ($apply_to_keys_also & & is_string ($key)) {$new_key = $function ($key); if ($new_key! = $key) {$array [$new_key] = $array [$key]; unset ($array [$key]) } $recursive_counter--;} function JSON ($array) {arrayRecursive ($array, 'urlencode', true); $json = json_encode ($array); return urldecode ($json);} $json_string=JSON ($data); / / $obj = json_decode ($json_string); print_r ($json_string)

After these processing, you will find that the Chinese characters read by the background PHP from the database have been successfully converted to json format and the Chinese language shows that everything is normal!

Of course, at this time, the data received by the front desk is in JSON format and the Chinese characters are normal!

All right, these are the ideas. There are many online methods! Look a little messy ~ mainly to remember the train of thought!

Then it depends on what function and what method to solve the related coding problem!

More annoying that kind of JS receptionist AJAX needs to transcode! Decode it backstage! Some need to turn twice!

What I have written so far is valid in the case of PHP background language code.

Even the foreground GBK does not need to do any transcoding operation, all only in the background PHP code to do the relevant conversion on it!

Thank you for reading this article carefully. I hope the article "how to get Chinese garbled codes from php ajax" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report