您的位置:首页 > 其它

用正则表达式得到一个页面的所有链接

2012-12-29 00:06 169 查看
只验证了href的链接,对于<script src=..></script>和<img src="">,mailto都不行,但是可以学一下正则表达式的应用

<html>

<head><title>正则表达式</title></head>

<body>

<a href="./">返回列表</a><br>

<form action="<?echo $PHP_SELF;?>" method="post">

URL:<input type="text" name="url" value="<?echo $url?>"><input type="submit" value="获取所有裢接">

</form>

<?

if(isset($url)){

echo "$url 有下列裢接:<br>";

$fcontents = file($url);

while(list(,$line)=each($fcontents)){

while(eregi('(href[[:space:]]*=[[:space:]]*"?[[:alnum:]:@/._-]+"?)(.*)',$line,$regs)){

$regs[1] = eregi_replace('(href[[:space:]]*=[[:space:]]*"?)([[:alnum:]:@/._-]+)("?)',"2",$regs[1]);

echo " $regs[1]<br>";

$line = $regs[2];

}

}

}

?>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: