parsing out links in HTML docs

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello to you all,

A question from a PHP newby who is disorientated by the overwhelming
amount of existing example scripts.

-- What is the best/simplest way to parse out the links in a a HTML
document and putting them in an array? --

Some hints, functions or snipplets would be highly appreciated.



Re: parsing out links in HTML docs

marco wrote:
Quoted text here. Click to load it

Here's a way:


$file = file_get_contents(" /");
preg_match_all("/<a[^>]+href\s*=\s*(\"|')?([^\"'\s>]+)/i", $file, $links);

print "<pre>";
print "</pre>";



Re: parsing out links in HTML docs

O Yeah, the one magic line...

<< preg_match_all("/<a[^>]+href\s*=\s*(\"|')?([^\"'\s>]+)/i", $file, $links); >>


Thanks a lot.


Site Timeline