How to convert some multibyte characters into its numeric html entity using PHP?

前端 未结 3 1208
挽巷
挽巷 2021-01-03 12:20

Test string:

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


        
相关标签:
3条回答
  • 2021-01-03 13:01

    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

    0 讨论(0)
  • 2021-01-03 13:09
    $encoded = mb_convert_encoding($s, 'HTML-ENTITIES', 'UTF-8'); 
    

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

    0 讨论(0)
  • 2021-01-03 13:11

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

    0 讨论(0)
提交回复
热议问题