ord()不适用于utf-8 [英] ord() doesn't work with utf-8

查看:124
本文介绍了ord()不适用于utf-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据ISO 8859-1

according to ISO 8859-1

€符号的十进制值为128

€ Symbol has decimal value 128

我的默认php脚本编码为

My default php script encoding is

echo mb_internal_encoding(); //ISO-8859-1

所以现在是PHP

echo chr(128);  //Output exactly what i want '€'

但是

echo ord('€');  //opposite it returns 226, it should be 128

为什么会这样?

推荐答案

根据维基百科文件格式

  • ISO-8859-1根本没有欧元符号
  • ISO-8859-15的代码点为164(0xA4)
  • Windows-1252在代码点128(0x80)上具有它
  • Unicode在代码点8364(0x20AC)上具有欧元符号
  • UTF-8将其编码为0xE2 0x82 0xAC.第一个字节E2是十进制的226.
  • ISO-8859-1 doesn't have the Euro symbol at all
  • ISO-8859-15 has it at codepoint 164 (0xA4)
  • Windows-1252 has it at codepoint 128 (0x80)
  • Unicode has the Euro symbol at codepoint 8364 (0x20AC)
  • UTF-8 encodes that as 0xE2 0x82 0xAC. The first byte E2 is 226 in decimal.

所以看来您的源文件是用UTF-8编码的(而ord()仅返回第一个字节),而您的输出是在Windows-1252中.

So it seems your source file is encoded in UTF-8 (and ord() only returns the first byte), whereas your output is in Windows-1252.

这篇关于ord()不适用于utf-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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