Re: Extracting urls from HTML
| From: | Jay Greenspan | Date: | Thu, 26 Oct 2000 01:58:14 +0000 |
| Subject: | Re: Extracting urls from HTML | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-22003@lists.php.net to get a copy of this message | ||
I think I'd use preg_match_all(). You can see the manual
for how it breaks up the array, which is pretty clost to what you're
looking for.
Something like this regular expression should work, I think.
You might have to make changes depending on how you
delimit your hrefs.
preg_match_all('/<a href="([^"]*)".*>(.*)<\/a>/i', $str,
$array);
"Srinivasan Ramakrishnan" wrote in message
<006d01c03edd$ef752420$ce87c5cb@srinivarmd3>...
>Hi,
>
>I need to extract the list of links from a html file.
>
>Ideally I will get them into an associative array where the name part
equals
>the text between <a href...> and </a>, and the value part contains the
>actual URL.
>
>I've been looking at the available string functions, and I can't seem to
>find a way. Is there a class or library that does this?
>
>I'm too lazy to figure out how to write a parser for this, atleast what I'm
>trying to do doesn't warrant that kind of effort. I have a pretty large
>bookmark file, and I want to store just the links and names in a text file.
>
>Thanks,
>
>Srini
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>For additional commands, e-mail: php-general-help@lists.php.net
>To contact the list administrators, e-mail: php-list-admin@lists.php.net
>