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

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

Test string:

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


        
3条回答
  •  长发绾君心
    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.

提交回复
热议问题