【发布时间】:2010-09-12 05:02:43
【问题描述】:
如何将 UTF-8 字符串(即 8 位字符串)转换为/从 XML 兼容的 7 位字符串(即带有数字实体的可打印 ASCII)?
即encode() 函数这样:
encode("“£”") -> "“£”"
decode() 也很有用:
decode("“£”") -> "“£”"
PHP 的 htmlenties()/html_entity_decode() 对没有做正确的事情:
htmlentities(html_entity_decode("“£”")) ->
"“£”"
费力地指定类型会有所帮助,但仍会返回与 XML 不兼容的命名实体,而不是数字实体:
htmlentities(html_entity_decode("“£”", ENT_QUOTES, "UTF-8"), ENT_QUOTES, "UTF-8") ->
"“£”"
【问题讨论】:
标签: php html xml unicode utf-8