Php+ajax solve Chinese garbled problem

Source: Internet
Author: User
Tags format php and

When the value of the parameter is English can be correctly written to the database, but for the Chinese is not, how to solve the problem of Chinese garbled?

Here's a step-by-step lesson If you solve PHP and AJAX development process, submit the Chinese parameter garbled problem.

The reason for this is because of the format problem passed by the parameter.
Because the English language in the parameter transfer to both sides of the format, so no problem.
In the Chinese state, there are structural combinatorial problems. There are similar traditional types of chaos.

You can solve this:
In JS, the parameters to be passed through encodeURIComponent (Var) first, this function conversion.

The incoming PHP uses $var =iconv ("UTF-8", "GB2312", $_get[' var '), and converts the accepted variable into Chinese.

Finally, when the PHP pass out the parameters of the function $var =iconv ("GB2312", "UTF-8", "Your message"), conversion once. The problem is solved.



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.