Cause Analysis of php garbled characters

Source: Internet
Author: User

 

Structure:

Index.html ---> ajax. js

Dispatch. php ----> addclassify. php -----> database. php

 

After index.html is opened, the page is displayed normally. Both Chinese and English are OK. Click Add. ajax. js sends the request to dispatch. dispatch is distributed to addclassify according to the request function code. This file is added and will use the functions in database. php. Then addclassify returns the result with echo. OK is returned for successful addition, and the error cause is returned for failed addition.

 

Strange things happen, and ajax always returns garbled characters.

 

Previously garbled characters were caused by inconsistent communication codes. However, my index. heml is UTF-8 and ajax is UTF-8. The default Character Set of php. ini is utf8.

Previously there was an html and php architecture, but the two programs run normally.

 

I woke up and thought of another possibility. This dispatch. php is garbled during storage on the server.

Ssh connection, vim, I see, x, your mom, html files are normal, all PHP files contain Chinese characters are garbled.

 

In windows, I use zend stuio to write php and dreamweaver to write html. That is to say, dreamweaver stores the webpage as utf8, and zend stuidio does not. Because the PHP file written by zend studio is saved as ANSI, Chinese characters are garbled after being uploaded to the server.

 

Temporary solution: open all the PHP files written by zend in notepad, and select UTF-8 when saving the files. OK.

Ultimate Solution: Modify zend studio settings. I use zend studio 9. The setting options may vary in different versions, and readers can find them by themselves.

Toolbar: project -----> properties in this window to see the Resource, modify the text file encoding to the UTF-8, save it.

Test:

Create a file 1.php in the project and enter the following code

 

 

1. <? Php

2. echo "Neural Network, Sha, 3, and so on ";

3.?>

Running result:

OK

 

From the boundless ocean of shyandsy

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.