Warning: preg_replace_callback(): Requires argument 2, 'iconv('UCS-2', 'UTF-8', pack('H4', '\1'))'
php 升级后(5.4升级到5.6)出现的错误
1)PHP message: PHP Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead
2)Warning: preg_replace_callback(): Requires argument 2, 'iconv('UCS-2', 'UTF-8',
参考:
http://www.jiawin.com/preg_replace_callback
解决办法:
$data = curl_menu(ACCESS_TOKEN, preg_replace("#\\\u([0-9a-f]+)#ie", "iconv('UCS-2', 'UTF-8', pack('H4', '\\1'))", $data));
替换如下:
function decodeUnicode($str){ return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', create_function('$matches', 'return iconv("UCS-2BE","UTF-8",pack("H*", $matches[1]));'), $str); }