问题
Test string:
$s = "convert this: ";
$s .= "–, —, †, ‡, •, ≤, ≥, μ, ₪, ©, ® y ™, ⅓, ⅔, ⅛, ⅜, ⅝, ⅞, ™, Ω, ℮, ∑, ⌂, ♀, ♂ ";
$s .= "but, not convert ordinary characters to entities";
回答1:
$encoded = mb_convert_encoding($s, 'HTML-ENTITIES', 'UTF-8');
asssuming your input string is UTF-8, this should encode most everything into numeric entities.
回答2:
Well htmlentities doesn't work correctly. Fortunately someone has posted code on the php website that seems to do the translation of multibyte characters properly
回答3:
I did work on decoding ascii into html coded text (&#xxxx). https://github.com/hellonearthis/ascii2web
来源:https://stackoverflow.com/questions/5123638/how-to-convert-some-multibyte-characters-into-its-numeric-html-entity-using-php