代码如下(自己页面编码是:utf-8,目标网页是iso-8859-1):
$url="http://www.amazon.cn/gp/product/B001UHNVR6/ref=ox_ya_os_product";
$text=file_get_contents($url);
$text1=iconv("iso-8859-1","utf-8",$text);
echo $text1;
结果是乱码;也用过$text1=utf8_encode($text) 转码,结果还是乱码,555。
不转码结果依然是乱码
请教怎么处理?谢谢各种前辈!
$url="http://www.amazon.cn/gp/product/B001UHNVR6/ref=ox_ya_os_product";
$text=file_get_contents($url);
$text1=iconv("iso-8859-1","utf-8",$text);
echo $text1;
结果是乱码;也用过$text1=utf8_encode($text) 转码,结果还是乱码,555。
不转码结果依然是乱码
请教怎么处理?谢谢各种前辈!
meta里是错的
$url="http://www.amazon.cn/gp/product/B001UHNVR6/ref=ox_ya_os_product";
$text=file_get_contents($url);
echo $text;
可是问题又来了
preg_match('#<span class="listprice">¥ (.*)</span>#iu',$text,$arr);
$sj=$arr[0]."元";
echo $sj;采集价格的时候,$sj=¥ 32.00元 死活多个“¥”想了无法办法都干不掉,怎么去掉呢?实在是感谢啊,小菜鸟诚心求教了。
$sj=$arr[1]."元";
echo $sj;
preg_match('#<span\s*class="listprice">¥ (.*)</span>#iu',$text,$arr);
$sj=$arr[1]."元";
echo $sj;
如果只是多了¥符号,替换一下也很容易啊 str_replace('¥', '', $sj);
<td class="vipPriLinPadd">
<span class="price">¥(.*)</span>#isu',$text,$arr);
$vj=$arr[1]."元";
echo $vj;
preg_match_all('#<span class="listprice">¥(.*)<\/span>#is',$text,$arr);
print_r($arr);
$sj=$arr[1][0]."元";
$sj1=$arr[1][1]."元";
echo $sj;
echo $sj1;
你正则里的¥是中文字符,也需要是utf-8,才能正确匹配.