如何使用PHP将一些多字节字符转换为其数字html实体?

时间:2011-02-25 22:58:58

标签: php string unicode utf-8 multibyte

测试字符串:

$s = "convert this: ";
$s .= "–, —, †, ‡, •, ≤, ≥, μ, ₪, ©, ® y ™, ⅓, ⅔, ⅛, ⅜, ⅝, ⅞, ™, Ω, ℮, ∑, ⌂, ♀, ♂ ";
$s .= "but, not convert ordinary characters to entities";

3 个答案:

答案 0 :(得分:11)

$encoded = mb_convert_encoding($s, 'HTML-ENTITIES', 'UTF-8'); 

假设您的输入字符串是UTF-8,这应该将大多数内容编码为数字实体。

答案 1 :(得分:0)

htmlentities无效。幸运的是,有人在php网站上posted code似乎正确地进行了多字节字符的翻译

答案 2 :(得分:0)

我确实将ascii解码为html编码文本(& #xxxx)。 https://github.com/hellonearthis/ascii2web

相关问题