Home > Backend Development > PHP Tutorial > Analysis of causes of php garbled code_PHP tutorial

Analysis of causes of php garbled code_PHP tutorial

WBOY
Release: 2016-07-13 17:47:57
Original
1120 people have browsed it

Structure:

index.html--->ajax.js

dispatch.php---->addclassify.php----->database.php

After opening index.html, the page displays normally, both Chinese and English are OK. Click Add, ajax.js sends a request to dispatch, dispatch is distributed to addclassify according to the request function code, this file is responsible for adding, and will use the functions in database.php, and then addclassify returns the result using echo. If the addition is successful, ok will be returned; if the addition fails, the error reason will be returned.

Something strange happened, the ajax return is always garbled.

In the past, garbled characters were caused by inconsistent communication encoding. But now my index.heml is utf-8, ajax is utf-8, and the default character set of php.ini is also utf8.

There was an HTML and PHP program with this architecture before, but those two programs ran normally.

When I woke up, I thought of another possibility. This dispatch.php is garbled when stored on the server.

SSH connected to it, and vim looked at it, I x your mother, the html files are normal, but the Chinese characters in all the php files are garbled.

I use zend stuio to write php under windows and dreamweaver to write html. That means Dreamweaver will store web pages in utf8, but Zend Studio will not. Because the PHP files written by Zend Studio are saved as ANSI, the Chinese characters will be garbled after being uploaded to the server.

Temporary solution: Open all PHP files written by zend with Notepad, and select UTF-8 when saving. OK.

Ultimate solution: modify zend studio settings. I am using zend studio 9. The location of this setting option may be different in different versions. Readers can find it themselves.

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

Under test:

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

1.

2. echo "Nerve, sway sahas, san ah, sa ye";

3. ?>

Running results:

OK

Excerpted from shyandsy’s boundless ocean

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478483.htmlTechArticle Structure: index.html---ajax.js dispatch.php----addclassify.php--- --database.php After opening index.html, the page displays normally, both Chinese and English are OK. Click Add, ajax.js sends the request to dis...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template