<?php
$url = 'http://luolai.tmall.com/search.htm?pageNum=1';  
$lines_array = file($url);  
echo $lines_array; echo "<br/>"; $lines_string = implode('', $lines_array);   
eregi("<title>(.*)</title>", $lines_string, $head); 
echo "head:".$head;  
echo "<br/>"; print_r($head); 
echo "<br/>";  
echo "title:".$head[1]; ?>
这个打印出来有乱码,如何才能不乱码?

解决方案 »

  1.   

    试试这个:<?php
    function file_get_contents_utf8($fn) {
    $content = file_get_contents($fn);
      return mb_convert_encoding($content, 'UTF-8', 
      mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
    }
    ?>
      

  2.   

    淘宝是gb2312编码,而你的是utf-8编码,因此就乱码了。
    echo "title:".iconv('gbk','utf-8',$head[1]); 
      

  3.   

    他的页面是 gb2312 的,而你的是 utf-8 的
    所以在打印前应做编码转换
    $head = iconv('gbk', 'utf-8', $head);
      

  4.   

    用iconv函数或者mb_convert_encoding函数转换整个网页file_get_contents显示不出乱码,但是用正则就是无法取出中间的中文字符串。
      

  5.   

    虽然有 Deprecated:  Function eregi() is deprecated in Array 错误警告
    但结果还是有的
    Array
    (
        [0] => <title>
                            宝贝列表页-罗莱家纺官方旗舰店--            天猫Tmall.com             </title>
        [1] => 
                            宝贝列表页-罗莱家纺官方旗舰店--            天猫Tmall.com             
    )
    <br/>title:
                            宝贝列表页-罗莱家纺官方旗舰店--            天猫Tmall.com