求助.. linux下的php采集程序无法访问外网怎么办?

解决方案 »

  1.   

    在linux下是可以访问外网的,也可以ping通,我把代码贴出来:
    $strurl="http://www.cma.gov.cn/tqyb/weatherdetail/58367.html";
    //$strurl="http://www.xishuiw.com/info/2009-2/2009-2-6-15879.htm";
    $wfileurl="../weather/".$date.".txt";
    function wstr($n) {
        return "http://www.cma.gov.cn".$n;
    }
    function wstr1($n) {
        return str_replace("/tqyb/img/weather/","/tqyb/img/weather/a",$n);
    }if(is_file($wfileurl))
    {
    $handle=fopen($wfileurl, "r");
    $weatherstr=fread($handle,filesize($wfileurl)); 
    fclose($handle);
    }
    else
    {

      $strhtmlarray=file($strurl); $strlinehtml= implode('%', $strhtmlarray); 
    eregi("3天预报(.*)指数查询", $strlinehtml, $head);
    preg_match_all("((/tqyb/img/weather/)([0-9]{1,2})\.(\gif))", $head[0],$wimgarr);
    $wimg = array_map("wstr", $wimgarr[0]);
    $wimgurl= implode('%', $wimg); 
    $wimg1 = array_map("wstr1", $wimg);
    $wimgurl1= implode('%', $wimg1); 
    $head[0]=strip_tags($head[0]);
    $head[0]=str_replace(" ","",$head[0]);
    $head[0]=str_replace("3天预报","",$head[0]);
    $head[0]=str_replace("时间","|",$head[0]);
    $head[0]=str_replace("天气概况","|",$head[0]);
    $head[0]=str_replace("气 温","|",$head[0]);
    $head[0]=str_replace("风向/风力","|",$head[0]);
    $head[0]=str_replace("指数查询","",$head[0]);
    $head[0]=str_replace(" ","",$head[0]);
    $head[0].="|".$wimgurl;
    $head[0].="|".$wimgurl1;
    $weatherstr=$head[0];
    $handle=fopen($wfileurl, "w"); 
    fwrite($handle,$weatherstr); 
    fclose($handle);
    }
    其中$strhtmlarray=file($strurl);在window下可以取到内容,但是在linux下就没有办法取到内容