欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Warning: preg_replace_callback(): Requires argument 2, 'iconv('UCS-2', 'UTF-8',

程序员文章站 2023-12-24 17:21:45
...

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); 
}

上一篇:

下一篇: