怎么用php获得一个网页的全部html源代码,需要从缓存调用吗?应该怎么做? $code = implode('',file('http://www.csdn.net/Expert/topic/487/487624.shtm')); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 网页是php生成的,需要获得他的html,应该怎么办?急~~~~ 给你这个试试!网页资料任你抓!哈哈!<? class CKimoInfo { var $datapath = "/data/kimo/"; //要暂存网页的位置 function GetdataPath(){ $inc=getenv("document_root"); //unix绝对路径 return $inc.$this->datapath; } function Kimoweather() { $filename= $this->getdatapath()."ware.txt"; $isf=is_file($filename); // 该档案不存在,或是该档案超过一段时间后才更新if(!$isf || ($isf && (time()-filemtime($filename)) > (60*3)) ) { //档案超过3hour才更新 $kimofile="http://news.kimo.com.tw/"; //要抓取的目标网页 $fcontents = join( '', file( "$kimofile" ) ); //分析你要的那一段 // 以本例: 我要抓介于<!-------x 和y -------之間的資料 $fcontents=ereg_replace("n","",$fcontents); preg_match_all("|(<!-------------x 和y end---------------->)|", $fcontents, $out); // 将多余不想要的字串过滤$out[0][0]=ereg_replace("/pic/","http://news.kimo.com.tw/pic/",$out[0][0]); $out[0][0]=ereg_replace("x","",$out[0][0]); // 存档 $fp = fopen ($filename, "w"); fwrite ($fp,$out[0][0]); fclose($fp); } //以后每次只要直接将该档案的字串抓來用就好了 if(is_file($filename)) { $fcontents = join( '', file( "$filename" ) ); //echo $fcontents; return $fcontents; } } } ?> 用法: $kimo=new CKimoInfo(); echo $kimo->Kimoweather(); 写了一大堆,实际上还是用 file()函数 在你设计PHP页面时就不要用html,全部由php echo即可。我的做法是使用模板,解析后页面就放在一个字符串中,想输出还是想生成cache页面都很简单。 个人认为PHP/ASP/JSP中html嵌入代码的方式是一种很不好的习惯。 那你就别用php了,用perl吧…… 多维数组数据,做下拉菜单,怎样读取对应ID的TEXT php 释放内存 如何赋予Mysql用户创建数据库的权限? 只有一行语句的页面,请问错在哪? 多个虚拟主机的问题谢谢关注 在输入两列的值后自动写入第三列? 关于绘制文字的问题 请教网页图像保密的解决方案 很多例子都是用gif格式,我用jpg格式,为什么提示“先生,要不要下载呀?” session 的用法 请问IIS 5.0的配置文件在那里?就像Apache的可以自己设置配置的ini 一个关于配置apache服务器的问题,各位高手帮帮忙!
<?
class CKimoInfo {
var $datapath = "/data/kimo/"; //要暂存网页的位置 function GetdataPath(){
$inc=getenv("document_root"); //unix绝对路径
return $inc.$this->datapath;
} function Kimoweather() {
$filename= $this->getdatapath()."ware.txt";
$isf=is_file($filename);
// 该档案不存在,或是该档案超过一段时间后才更新
if(!$isf || ($isf && (time()-filemtime($filename)) > (60*3)) ) { //档案超过3hour才更新
$kimofile="http://news.kimo.com.tw/"; //要抓取的目标网页
$fcontents = join( '', file( "$kimofile" ) );
//分析你要的那一段
// 以本例: 我要抓介于<!-------x 和y -------之間的資料
$fcontents=ereg_replace("n","",$fcontents);
preg_match_all("|(<!-------------x 和y end---------------->)|", $fcontents, $out);
// 将多余不想要的字串过滤
$out[0][0]=ereg_replace("/pic/","http://news.kimo.com.tw/pic/",$out[0][0]);
$out[0][0]=ereg_replace("x","",$out[0][0]);
// 存档
$fp = fopen ($filename, "w");
fwrite ($fp,$out[0][0]);
fclose($fp); }
//以后每次只要直接将该档案的字串抓來用就好了
if(is_file($filename)) {
$fcontents = join( '', file( "$filename" ) );
//echo $fcontents;
return $fcontents;
}
} } ?> 用法:
$kimo=new CKimoInfo();
echo $kimo->Kimoweather();
我的做法是使用模板,解析后页面就放在一个字符串中,想输出还是想生成cache页面都很简单。