<?
/*
* Programmer :
* Window
*/ function fetch_urlpage_contents($url){
$c=file_get_contents($url);
return $c;
}
//获取匹配内容
function fetch_match_contents($begin,$end,$c)
{
$begin=change_match_string($begin);
$end=change_match_string($end);
if(@preg_match("/{$begin}(.*?){$end}/i",$c,$rs))
{return $rs[1];}
else {return "";}
}//转义正则表达式字符串
function change_match_string($str){
//注意,以下只是简单转义
$old=array("/","$");
$new=array("\/","\$");
$str=str_replace($old,$new,$str);
return $str;
} //采集网页
function pick($url,$ft,$th)
{
$c=fetch_urlpage_contents($url);
foreach($ft as $key => $value)
{
$rs[$key]=fetch_match_contents($value["begin"],$value["end"],$c);
if(is_array($th[$key]))
{ foreach($th[$key] as $old => $new)
{
$rs[$key]=str_replace($old,$new,$rs[$key]);
}
}
}
return $rs;
}
$url="http://www.baidu.com"; //要采集的地址
$ft["title"]["begin"]="<title>"; //截取的开始点
$ft["title"]["end"]="</title>"; //截取的结束点
$th["title"]["百度"]="千度"; //截取部分的替换///////////////
$rs=pick($url,$ft,$th); //开始采集 echo $rs["title"]; //输出 ?>
/*
* Programmer :
* Window
*/ function fetch_urlpage_contents($url){
$c=file_get_contents($url);
return $c;
}
//获取匹配内容
function fetch_match_contents($begin,$end,$c)
{
$begin=change_match_string($begin);
$end=change_match_string($end);
if(@preg_match("/{$begin}(.*?){$end}/i",$c,$rs))
{return $rs[1];}
else {return "";}
}//转义正则表达式字符串
function change_match_string($str){
//注意,以下只是简单转义
$old=array("/","$");
$new=array("\/","\$");
$str=str_replace($old,$new,$str);
return $str;
} //采集网页
function pick($url,$ft,$th)
{
$c=fetch_urlpage_contents($url);
foreach($ft as $key => $value)
{
$rs[$key]=fetch_match_contents($value["begin"],$value["end"],$c);
if(is_array($th[$key]))
{ foreach($th[$key] as $old => $new)
{
$rs[$key]=str_replace($old,$new,$rs[$key]);
}
}
}
return $rs;
}
$url="http://www.baidu.com"; //要采集的地址
$ft["title"]["begin"]="<title>"; //截取的开始点
$ft["title"]["end"]="</title>"; //截取的结束点
$th["title"]["百度"]="千度"; //截取部分的替换///////////////
$rs=pick($url,$ft,$th); //开始采集 echo $rs["title"]; //输出 ?>
解决方案 »
- 各位大哥大姐我想在网站后台的编辑器里面插入左边是文字右边是图片让他们合并在一行上怎么弄啊?那编辑器不支持CSS样式
- 寻php程序员合作
- Oracle 导出的txt数据如何导入到另一个MySQL数据库中
- php判断输出
- 请教高手PHP编写单点登陆程序
- ecshop后台商品状态不能单个修改,能批量的修改掉。急急急
- 现在论坛上的人好像少了很多啊
- zendstudio调试 装了zend,要调试还再次安装PHP环境吗?MySQL也要重装吗?
- 写一个程序,用来增删改一张图片上的城市
- 我刚刚搭建了个centos6.0平台有问题!
- IIS5.0+PHP5.2+MYSQL+PHPMyAdmin 数据出错怎么处理
- PHP学用代码大全
采集用CURL,正则等