2011-07-16 37 views

回答

2

有没有(命名)实体的字符。您可以看到列表here。如果您想转换为数字实体,请参阅this answer

+0

向您推荐的替代功能encode2()产生以下错误:解析错误:语法错误,意外的T_FUNCTION,期望')'在调用array_map的行上 –

+0

@ A-OK它是为PHP 5.3编写的。 – Artefacto

2

“ć”的字符代码是263,其作为HTML实体是ć等等。

+0

使用htmlentities转换第一个字符,然后使用'preg_replace_callback'和正则表达式'“/ [^ \ x00- \ x7F] /”'第二遍转换任何超出ASCII范围的字符。 – MRAB

2

众所周知,某些字符未用htmlentities();编码。

如果你看一下docs,也有一些职位与角色地图,你可以用str_replace()

2
<?php 

function encode($string) { 
    return mb_encode_numericentity($string, array(0x000000, 0x10ffff, 0, 0xffffff), 'UTF-8'); 
} 

echo encode('ćĆČ芚ĐđŽž'); 

结果用的是&#263;&#262;&#268;&#269;&#352;&#353;&#272;&#273;&#381;&#382;

+0

该死!搜索几个小时后,你的回答救了我:) – Avik

相关问题