cmd的字符集 [英] cmd's character set

查看:191
本文介绍了cmd的字符集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  C:\Users\Kolink> php -recho'é'; 
Ú

C:\Users\Kolink> echoé
é

如你所见,输出é的程序会产生Ú使用 echo 命令给出所需的字符。



然后,我可以配置PHP

CMD.exe在PHP中的工作原理是不同的代码页。顺便说一下,它也是与默认Windows代码页不同的代码页。这是为了与旧的MS-DOS程序兼容。在我的国家Windows使用Windows-1250和cmd.exe使用DOS Latin2。我想在英国这将是Windows-1252和DOS Latin1分别。



为了得到相同的结果,你必须使用相同的代码页在PHP和cmd.exe。检查PHP使用的代码页,并将cmd.exe设置为同一个代码页。为此,请使用以下命令: mode con sp select =< codepagenumber> chcp< codepagenumber> 。这将更改cmd.exe的当前实例的代码页。



以下是一些典型代码页及其数字的简短列表:

  DOS Latin1 850 
DOS Latin2 852
Windows-1250 1250
Windows-1252 1252
UTF-8 65001
ISO-8859-1 28591
ISO-8859-2 28592

正如@Christophe Weis在注释中指出的, 代码页标识符的其他代码页页面。


C:\Users\Kolink>php -r "echo 'é';"
Ú

C:\Users\Kolink>echo é
é

As you can see, a program outputting an é results in a Ú, but using the echo command gives the desired character.

And, can I configure PHP (maybe some command at the start of the script) to output the correct character?

解决方案

CMD.exe works in different codepage than PHP. By the way, it is also different codepage than default Windows codepage. This is for compatibility with older MS-DOS programs. In my country Windows uses Windows-1250 and cmd.exe uses DOS Latin2. I suppose in UK this would be Windows-1252 and DOS Latin1 respectively.

To get the same results you have to use the same codepage in PHP and in cmd.exe. Check what codepage is used by PHP and set cmd.exe to the same codepage. To do this, use the following command: mode con sp select=<codepagenumber> or chcp <codepagenumber>. This will change the codepage only for the current instance of cmd.exe.

Here is a short list of some typical codepages and their numbers:

DOS Latin1    850
DOS Latin2    852
Windows-1250  1250
Windows-1252  1252
UTF-8         65001
ISO-8859-1    28591
ISO-8859-2    28592

As @Christophe Weis pointed out in comments, you can lookup the identifiers of other code pages at Code page identifiers page.

这篇关于cmd的字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆