我正在尝试压缩以下的链接,它在GBK中。我想提取产品和图像的标题。但是,当我回音文档来测试它是否工作时,我就不懂汉字了。我需要提取使用domxpath和显示字符在我的网站上,相同的字符,而不是奇怪的字符。这到底是怎么回事?
$ch = curl_init("http://item.taobao.com/item.htm?spm=a2106.m874.1000384.41.aG3Kbi&id=20811635147&_u=o1ffj7oi9ad3&scm=1029.newlist-0.1.16&ppath=&sku=");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);
$doc = new DOMDocument();
$searchPage = mb_convert_encoding($content, 'utf-8', "auto");
$doc->loadHTML($searchPage);
echo $doc->saveHTML(); 发布于 2013-07-24 02:25:18
检查mbstring.language在php.ini中是否设置为GBK,或显式使用
$searchPage = mb_convert_encoding($content, 'utf-8', "gb18030");发布于 2014-01-03 08:59:37
我也有同样的问题。解决方案对我来说是可行的:
$str = file_get_contents($url);
$str = mb_convert_encoding($str,'utf-8', "gb18030");
$str = str_replace('<head>', '<head><meta HTTP-EQUIV=Content-Type content="text/html;charset=utf-8">', $str);
$dom = new DOMDocument('1.0');
@$dom->loadHTML($str);DOMDocument以html格式读取您的编码声明,并将其放在头后面。
https://stackoverflow.com/questions/17823947
复制相似问题