我想从桌子上找出我的产品的名字。
但我找不到西里尔字母的名字。
解析时我用的是ganon。
当我尝试输出带有名称的数组时,必须包含西里尔字符的所有值都是空的。为什么?
请帮我修一下。
$url = "http://www.plati.ru/asp/block_goods_s.asp?id_r=0&id_s=252900&sort=name&page=1&rows=10&curr=EUR&lang=ru-RU&rnd=1544554";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/7.0");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50);
$result = curl_exec($ch);
$redir = curl_getinfo($ch, CURLINFO_HEADER_OUT);
curl_close($ch);
$html = str_get_dom($result);
foreach ($html('.link_good_tab') as $element) {
$temp = str_replace("\xA0", ' ', $element->getPlainText());
$products[] = iconv(mb_detect_encoding($temp, mb_detect_order(), true), "UTF-8", $temp);
}
echo "<pre>";
print_r($products);
echo "</pre>";这是结果
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] => C&C: Red Alert 3 - Uprising (Origin/RegFree/Multilang)发布于 2014-09-08 07:48:54
因为您已经知道了编码,所以只需自己设置它,您也可以使用mb_convert_encoding()。示例:
$ch = curl_init('http://www.plati.ru/asp/block_goods_s.asp?id_r=0&id_s=252900&sort=name&page=1&rows=10&curr=EUR&lang=ru-RU&rnd=1544554');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
$html = str_get_dom($result);
foreach ($html('.link_good_tab') as $element) {
$temp = str_replace("\xA0", ' ', $element->getPlainText());
$products[] = mb_convert_encoding($temp, "utf-8", "windows-1251");
}
echo "<pre>";
print_r($products);
echo "</pre>";发布于 2014-09-08 07:53:53
在我的计算机中,命令()返回以下内容:
array (
0 => 'ASCII',
1 => 'UTF-8',
)您的系统中的输出可能是类似的(即根本不包括Windows1251)。
如果您显然已经知道编码是哪一种,那么不确定为什么需要自动检测编码,但是如果需要的话,您应该使用远程服务器返回的Content-Type头,或者最多使用相应的<meta>标记。
https://stackoverflow.com/questions/25719359
复制相似问题