代码如下(自己页面编码是: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。
不转码结果依然是乱码
请教怎么处理?谢谢各种前辈!

解决方案 »

  1.   

    它实际上也是utf8, 
    meta里是错的
      

  2.   

    这个网页本身就是UTF-8编码的。
      

  3.   

    header("Content-Type: text/html; charset=utf-8");
    $url="http://www.amazon.cn/gp/product/B001UHNVR6/ref=ox_ya_os_product";
    $text=file_get_contents($url);
    echo $text;
      

  4.   

    谢谢,原来加个header("Content-Type: text/html; charset=utf-8"); 就可以了
    可是问题又来了
    preg_match('#<span  class="listprice">¥ (.*)</span>#iu',$text,$arr);
    $sj=$arr[0]."元";
    echo $sj;采集价格的时候,$sj=¥ 32.00元 死活多个“¥”想了无法办法都干不掉,怎么去掉呢?实在是感谢啊,小菜鸟诚心求教了。
      

  5.   

    preg_match('#<span class="listprice">¥ (.*)</span>#iu',$text,$arr);
    $sj=$arr[1]."元";
    echo $sj;
      

  6.   

    改成这样好了
    preg_match('#<span\s*class="listprice">¥ (.*)</span>#iu',$text,$arr);
    $sj=$arr[1]."元";
    echo $sj;
    如果只是多了¥符号,替换一下也很容易啊 str_replace('¥', '', $sj);
      

  7.   

    好神奇,那这个多行的怎么写呢?preg_match('#VIP 价:</td>.
     <td class="vipPriLinPadd">
       <span class="price">¥(.*)</span>#isu',$text,$arr);
    $vj=$arr[1]."元";
    echo $vj;
      

  8.   

    多行用preg_match_all
    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;
      

  9.   

    注意编码,对方的编码是utf-8.
    你正则里的¥是中文字符,也需要是utf-8,才能正确匹配.