Home >Backend Development >PHP Problem >What should I do if cmd outputs garbled characters when running a php file?

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

王林
王林Original
2020-07-10 11:23:544121browse

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;
?>

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!

Statement:
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