代码:
$html = preg_replace_callback("/(?[\x{4e00}-\x{9fa5}]+)/u",array("self","wyc_chinese"),$html);
...
省略
...
public function wyc_chinese($matches)
{
return $matches['chinese'].'(Chinese)';
}
问题:
$html为要提取的网页数据
如果$html是utf8编码的,则以上代码能正常执行(即能正常提取中文),但如果是其他编码的,则没法正常执行(无法匹配到汉字)
使用iconv转换$html的编码格式,也无法正常提取中文。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
认证0级讲师