获得某个网页上的所有超裢接

来源:互联网 发布:移动卡数据打不开 编辑:程序博客网 时间:2024/06/14 11:38
正则表达式例子:获得某个网页上的所有超裢接

<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 "&nbsp;&nbsp;&nbsp;&nbsp;$regs[1]<br>";
            $line = $regs[2];
        }
    }
}
?>
</body>
</html>

原创粉丝点击