2

测试字符串:

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

3 回答 3

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

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

于 2011-02-25T23:05:41.303 回答
0

那么htmlentities不能正常工作。幸运的是,有人在 php 网站上发布了似乎可以正确翻译多字节字符的代码

于 2011-02-25T23:03:54.903 回答
0

I did work on decoding ascii into html coded text (&#xxxx). https://github.com/hellonearthis/ascii2web

于 2011-02-26T09:45:16.467 回答