1
我有PHP 5.5中的問題:當我使用此代碼:警告:preg_replace_callback():修改/ E不能與更換回調使用
$source = preg_replace('/&#(\d+);/me', "utf8_encode(chr(\\1))", $source);
$source = preg_replace('/&#x([a-f0-9]+);/mei', "utf8_encode(chr(0x\\1))", $source);
返回錯誤
推薦使用:的preg_replace ():該/ e修飾符已過時,使用preg_replace_callback代替
我與preg_replace_callback使用:
$source = preg_replace_callback('/&#(\d+);/me', function($m) { return utf8_encode(chr($m[1])); },$source);
$source = preg_replace_callback('/&#x([a-f0-9]+);/mei', function($m) { return utf8_encode(chr("0x".$m[1])); },$source);
它返回警告:
警告:preg_replace_callback():修改/ E不能與更換回調使用
什麼將是實現這一目標的正確的代碼?
的問題是與''e'(修改)'你用'preg_replace_callback一起使用'regex'模式中()'function.Remove來自你的正則表達式的'e'(修飾符)'。所以簡單的代碼看起來像'preg_replace_callback('/&#(\ d +);/m',function($ m){return utf8_encode(chr($ m [1]));},$ source);' –
感謝您的支持,它的工作。 –