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

How to solve the problem of garbled data submitted by php json

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

Share

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

This article mainly explains how to solve the problem of data garbled submitted by php json. The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to solve the problem of data garbled submitted by php json.

1. Ensure that the database and the front and background PHP pages are coded in the same way.

The simplest way to solve the PHP JSON Chinese garbled code is to ensure that the database code and PHP page code are unified in UTF8 format. For PHP starter learners, it is best to use UTF8 format when setting up the database, which can reduce a lot of trouble.

2. Configure to use PHP function urlencode and JS function decodeURI ().

When PHP uses JSON to interact with foreground JS, it needs to use urlencode function to encode URL before using json_encode function, and read Chinese information after JS client uses JS function decodeURI () to decode URL.

Note: when interacting through JSON in a PHP page, such as converting an array to JSON format, first use the urlencode function to URL encode the array key and value, and then use the json_encode function and urldecode function.

3. Use string encoding conversion function.

When the database encoding and PHP page encoding are inconsistent due to various reasons, such as the existing database encoding uses GB2312, when using JSON interaction, it is necessary to use the string encoding conversion function to convert between character sets. The commonly used function is iconv, because iconv needs PHP configuration environment support, if not, you can write gbk and UTF8 transcoding functions to achieve transcoding.

At this point, the PHP JSON Chinese character garbled three solutions are introduced, in fact, in PHP development, encountered similar PHP and AJAX/JS interaction, generate Chinese garbled basically use these methods, the idea is similar.

Thank you for your reading, the above is the content of "how to solve the problem of data garbled submitted by php json". After the study of this article, I believe you have a deeper understanding of how to solve the problem of data garbled submitted by php json, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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