php5.5 preg_replace 使用e问题,改写成preg_replace_callback

publicfunctionentity_decode($str,$charset='UTF-8')
{
if(stristr($str,'&')===FALSE)
{
return$str;
}
$str=html_entity_decode($str,ENT_COMPAT,$charset);
$str=preg_replace('~&#x(0*[0-9a-f]{2,5})~ei','chr(hexdec("\\1"))',$str);
returnpreg_replace('~&#([0-9]{2,4})~e','chr(\\1)',$str);
}
麻烦使用preg_replace_callback改写下该方法,谢谢。
UYOU
浏览 303回答 1
1回答

江户川乱折腾

phppublicfunctionentity_decode($str,$charset='UTF-8'){if(stristr($str,'&')===false){return$str;}$str=html_entity_decode($str,ENT_COMPAT,$charset);$str=preg_replace_callback('/&#x(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);}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript