测试字符串:
$s = "convert this: ";
$s .= "–, —, †, ‡, •, ≤, ≥, μ, ₪, ©, ® y ™, ⅓, ⅔, ⅛, ⅜, ⅝, ⅞, ™, Ω, ℮, ∑, ⌂, ♀, ♂ ";
$s .= "but, not convert ordinary characters to entities";
$encoded = mb_convert_encoding($s, 'HTML-ENTITIES', 'UTF-8');
假设您的输入字符串是 UTF-8,这应该将大多数内容编码为数字实体。
那么htmlentities不能正常工作。幸运的是,有人在 php 网站上发布了似乎可以正确翻译多字节字符的代码
I did work on decoding ascii into html coded text (&#xxxx). https://github.com/hellonearthis/ascii2web