Support: nginx + php Chinese characters are always garbled

Source: Internet
Author: User
For help: nginx + php Chinese characters are always garbled and already tried:
1. Changing the Linux character set to zh_cn.utf-8
2. charset in nginx has been set to UTF-8
3. php files are stored in UTF-8 format.
4. added the php file header


However, Chinese characters cannot be displayed when a webpage is opened.

The PHP file is as follows:






@ Header ('content-type: text/html; charset = UTF-8 ');
Echo "my first PHP script! ";
?>



The webpage output is:
????? PHP ??!


Reply to discussion (solution)

Add:
If you open a UTF-8 text file on the server, Chinese characters are displayed normally.



Two fewer"



Two fewer"



Thank you!
I haven't changed it. it's still the same. All Chinese characters have become?




Two fewer"



Thank you!
I haven't changed it. it's still the same. All Chinese characters have become?






Two fewer"



Thank you!
I haven't changed it. it's still the same. All Chinese characters have become?


Sorry, I made a mistake! This is because the header code has been written in the configuration file for a long time. I just read it!
Header ("Content-Type: text/html; charset = utf-8"); // This should be written in the header of the PHP file.

  
 





Two fewer"



Thank you!
I haven't changed it. it's still the same. All Chinese characters have become?






Two fewer"



Thank you!
I haven't changed it. it's still the same. All Chinese characters have become?


Sorry, I made a mistake! This is because the header code has been written in the configuration file for a long time. I just read it!
Header ("Content-Type: text/html; charset = utf-8"); // This should be written in the header of the PHP file.

  
 



Thank you. Is the php header written in front of the entire file?
Does it work if I write it below?

Header ('content-type: text/html; charset = UTF-8 ');
?>





Echo "my first PHP script! ";
?>



In addition, these php files run normally on the apache server and can display Chinese characters.

I think there is something wrong with the settings on the server. Please kindly advise me!

There is a major discovery. I use DW to generate a new php to display Chinese characters.
Previously, I used the code written on a WordPad, but I couldn't do it. open it in DW again. see if the content generated by DW is copied to the old file for storage or garbled characters.

There is a solution, but it won't work if it is written for the Mao wordboard?

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.