测试字符串:
$s = "convert this: ";
$s .= "–, —, †, ‡, •, ≤, ≥, μ, ₪, ©, ® y ™, ⅓, ⅔, ⅛, ⅜, ⅝, ⅞, ™, Ω, ℮, ∑, ⌂, ♀, ♂ ";
$s .= "but, not convert ordinary characters to entities";
答案 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