如何将字符串中的所有字符转换为HTML实体?
htmlentities() 不适用于 ćĆČ芚Đ𮾠这样的字符
最佳答案
<?php
function encode($string) {
return mb_encode_numericentity($string, array(0x000000, 0x10ffff, 0, 0xffffff), 'UTF-8');
}
echo encode('ćĆČ芚ĐđŽž');
结果是 ćĆČ芚ĐđŽž
关于PHP:将所有字符转换为 HTML 实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6720826/