Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)归海一刀
published in(发表于) 2014/2/17 7:37:08
PHP教程:PHP读取某站点的链接的函数_[PHP教程]

PHP教程:PHP读取某站点的链接的函数_[PHP教程]

原理:读取某站点的源文件,再利用正则分析其源代码,得到所有链接
if(empty(url))url = "/";//设置url
site=substr(url,0,strpos(url,"/",8));//站点
base=substr(url,0,strrpos(url,"/")+1);//文件所在目录

fp = fopen(url, "r" );//打开url
while(!feof(fp))contents.=fread(fp,1024);//

pattern="|href=['"]?([^ '"]+)['" ]|U";
preg_match_all(pattern,contents, regArr, PREG_SET_ORDER);//匹配所有href=
for(i=0;iif(!eregi("://",regArr[i][1]))//是否是相对路径,即是否还有://
if(substr(regArr[i][1],0,1)=="/")//是否是站点的根目录
echo "link".(i+1).":".site.regArr[i][1]."
";//根目录
else
echo "link".(i+1).":".base.regArr[i][1]."
";//当前目录
else
echo "link".(i+1).":".regArr[i][1]."
";//相对路径
}
fclose(fp);
?>

来源:网络







If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759