How do I extract link text from anchor tag as well as the URL from the "href" attribute

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have the following code to extract the URLs from the anchor tags of an
HTML page:

$html = new DOMDocument();
$htmlpage->loadHtmlFile($location);
$xpath = new DOMXPath($htmlpage);
$links = $xpath->query( '//a' );
foreach ($links as $link)
{ $int_url_list[$i++] = $link->getAttribute( 'href' ) . "\n"; }

If I have a link <a href="http://X.com";>YYYY</a>, how do I extract the
corresponding YYYY which is displayed to the user as the text of the link
(if it's an image tag, I would like a DOMElement for that).
Thanks

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux