下面提供二款关于php正则链接方法,他们可以-取得内容所有链接并且保存到一个数组,当然也可以把链接全部替换哦。
下面提供二款关于php教程正则链接方法,他们可以-取得内容所有链接并且保存到一个数组,当然也可以把链接全部替换哦。
方法一
function get_all_url($code){
preg_match_all('/"' ]+)["|']?s*[^>]*>([^>]+)/i',$code,$arr);
return array('name'=>$arr[2],'url'=>$arr[1]);
}+href=["|']?([^>
方法二
$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;$i
($regarr);$i++){> if(!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);

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools

SublimeText3 Chinese version
Chinese version, very easy to use

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!
