解決辦法有多個,比如使用wsl,git的bash,而我要介紹的是使用原始的cmd解決utf-8編碼的問題,一般情況下我們在terminal 下執行php文件,如果里面有中文就會顯示亂碼,像下面這樣
Options:
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
auto_off 姣忓垎閽熸嫻嬩竴嬈″渾緇囨満涓嬫満鏁版嵁
automatic_deduction 姣忓ぉ8:50媯€嫻嬩竴嬈℃墍鏈夊叕鍙哥殑濂楅璧勮垂鎯呭喌騫舵墸璐
這是因為cmd默認使用的編碼是gbk(代碼936)
F:\>chcp
活動代碼頁: 936
解決思路就是把這里的編碼改為utf-8(65001)即可,之后在運行腳本就是正常的顯示了
F:\>chcp 65001
Active code page: 65001
...
Options:
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
auto_off 每分鍾檢測一次***
automatic_deduction 每天8:50檢測一次***
那么在terminal如何處理呢?
打開File->Settings->Tools->Terminal
,將Application settings
下的Shell path
設為cmd.exe /k chcp 65001 & cls
以后就不用管文字編碼的問題,愉快地coding吧