求助.. linux下的php采集程序无法访问外网怎么办? 求助.. linux下的php采集程序无法访问外网怎么办? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在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下就没有办法取到内容 替换源码中获取后的URL的问题! 文本输入框 ThinkPHP用include file引入模板后,动态内容不执行,怎么办呢 校内网开发接口方面 PHP 检测文件是否存在 php四级联动的问题如何解决啊!愁啊愁! PHP上传问题 while 循环跳转问题 谁有带数据库支持的bbs的代码啊? 新手求支招 YII 框架上如何调用控制台执行php文件 php+mysql问题 PHP不能使用domxml_open_mem() 方法,在哪下载php_iconv.dll,php_domxml.dll文件
$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下就没有办法取到内容