You might also want to try using the Raxan framework:

require_once 'raxan/pdi/gateway.php';

$page = new RichWebPage('page.html');
echo $page['a']->text(); // this will get the text betwen the a tag
To get the image element use:

$elm = $page['a img']->node(0);

You can download Raxan here:

Raymond Irving

--- On Sat, 8/22/09, Manuel Lemos <mle...@acm.org> wrote:

From: Manuel Lemos <mle...@acm.org>
Subject: [PHP] Re: How do I extract link text from anchor tag as well as the 
URL from the "href" attribute
To: "chrysanhy" <phpli...@hyphusonline.com>
Cc: php-general@lists.php.net
Date: Saturday, August 22, 2009, 1:07 AM


on 08/16/2009 04:33 AM chrysanhy said the following:
> 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

You may want to try this HTML parser class that comes with filter class
and an example script named test_get_html_links.php  that does exactly
what you ask.



Manuel Lemos

Find and post PHP jobs

PHP Classes - Free ready to use OOP components written in PHP

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to