search
Homephp教程php手册PHP读取某站点的链接

PHP读取某站点的链接

Jun 13, 2016 am 10:22 AM
phpanalyzeprincipleregularsource codeSource FileofsitereadLink


原理:读取某站点的源文件,再利用正则分析其源代码,得到所有链接

/**********qiushuiwuhen(2002-5-20)***********/
if(empty($url))$url = "http://www.csdn.net/expert/";//设置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);
?>

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor