Home  >  Article  >  Backend Development  >  Solution to gitbash PHP execution output with random Chinese encoding

Solution to gitbash PHP execution output with random Chinese encoding

藏色散人
藏色散人forward
2019-10-09 13:37:022983browse

Problem

During the development process, it is often necessary to execute the PHP script written under the test in gitbash under Windows. If there is Chinese output in the script, garbled characters will appear. This problem has been bothering me for a long time.

Processing method

1. Check whether the PHP installation path exists in the system through My Computer》Properties》Advanced System Settings》Environment Variables. If it exists, remove it. , this point is very critical, otherwise there will still be garbled characters;

2. After the first step is completed, open gitbash and execute echo $PATH to confirm whether the PHP path still exists in the environment variable; if it exists, please Go to Computer>Properties>Advanced Properties>Environment Variables to check whether they are completely removed;

3. By executing in gitbash, add the following content to vim ~/.bashrc (set the encoding of the environment and add the path to PHP to the environment variables)

export.utf-8
export PATH="$PATH:/f/phpStudy/PHPTutorial/php/php-7.0.12-nts"

4. Execute source ~/.bashrc and close it again, then open gitbash

5. Execute php test.php and try to output Chinese. Is it successfully solved? There is a problem with Chinese garbled characters.

The above is the detailed content of Solution to gitbash PHP execution output with random Chinese encoding. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete