Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- Regex to find URLs in <a> tags


brotherhood_of_LAN - 2:50 pm on Jul 3, 2011 (gmt 0)


Using regex to match HTML can get messy. Using PHP's DOM [php.net] functions might be easier. I found them a bit awkward to get to grips with but they bypass a lot of hassle in trying to parse documents.

<?php

$dom = new DOMDocument;
$dom->loadHTML($htmlstring);
 
// echo Links and their anchor text
echo '<pre>';
echo "Link\tAnchor\n";
foreach($dom->getElementsByTagName('a') as $link)
{
$href = $link->getAttribute('href');
$anchor = $link->nodeValue;
echo $href,"\t",$anchor,"\n";
// Do something here
}
echo '</pre>';

?>


Thread source:: http://www.webmasterworld.com/php/4334407.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com