publicfunctionentity_decode($str,$charset='UTF-8'){if(stristr($str,'&')===FALSE){return$str;}$str=html_entity_decode($str,ENT_COMPAT,$charset);$str=preg_replace('~(0*[0-9a-f]{2,5})~ei','chr(hexdec("\\1"))',$str);returnpreg_replace('~([0-9]{2,4})~e','chr(\\1)',$str);}麻烦使用preg_replace_callback改写下该方法,谢谢。
1 回答
江户川乱折腾
TA贡献1851条经验 获得超5个赞
phppublicfunctionentity_decode($str,$charset='UTF-8'){if(stristr($str,'&')===false){return$str;}$str=html_entity_decode($str,ENT_COMPAT,$charset);$str=preg_replace_callback('/(0*[0-9a-f]{2,5})/i',function($matches){returnchr(hexdec($matches[1]));},$str);returnpreg_replace_callback('/([0-9]{2,4})/',function($matches){returnchr($matches[1]);},$str);}
添加回答
举报
0/150
提交
取消