How to convert some multibyte characters into its

2020-02-29 11:12发布

Test string:

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

3条回答
太酷不给撩
2楼-- · 2020-02-29 11:25
$encoded = mb_convert_encoding($s, 'HTML-ENTITIES', 'UTF-8'); 

asssuming your input string is UTF-8, this should encode most everything into numeric entities.

查看更多
Viruses.
3楼-- · 2020-02-29 11:34

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

查看更多
聊天终结者
4楼-- · 2020-02-29 11:46

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

查看更多
登录 后发表回答