开发者

Get all link from a html

In PHP how can I get all link from a HTML document.

For example: <a href="w开发者_如何学编程ww.blabla.com">To Bla</a>

In php I need the link: www.blabla.com.

Thanks for your helps.


Maybe this will help: http://www.the-art-of-web.com/php/parse-links/

Summary:

<?php

// Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.

$url = "http://www.example.net/somepage.html";
$input = @file_get_contents($url) or die("Could not access file: $url");
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
if(preg_match_all("/$regexp/siU", $input, $matches)) {
    // $matches[2] = array of link addresses
    // $matches[3] = array of link text - including HTML code
}

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜