Home >Backend Development >PHP Problem >What should I do if cmd outputs garbled characters when running a php file?
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.
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:
2. Execute the chcp 65001 command , and then execute the php file again, you can see that the output is normal.
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!