What should I do if cmd outputs garbled characters when running a php file?

王林
Release: 2023-03-02 09:44:02
Original
4081 people have browsed it

The solution to the garbled output of cmd when running PHP files is: 1. Set the encoding, the specific code is [header("Content-type: text/html; charset=utf-8")]; 2. Execute [ chcp 65001] command; 3. Re-execute the php file.

What should I do if cmd outputs garbled characters when running a php file?

Solution:

(Recommended tutorial: php tutorial)

1. Set utf -8 encoding, the code is as follows:

<?php  
    header("Content-type: text/html; charset=utf-8"); 
    echo "中国";die;
?>
Copy after login

You can see at this time that the output result is still garbled:

What should I do if cmd outputs garbled characters when running a php file?

2. Execute the chcp 65001 command , and then execute the php file again, you can see that the output is normal.

What should I do if cmd outputs garbled characters when running a php file?

The above is the detailed content of What should I do if cmd outputs garbled characters when running a php file?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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