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

From: Date: Sun, 23 Aug 2009 02:56:41 +0000
Subject: Re: Re: How do I extract link text from anchor tag as well as the URL from the "href" attribute
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-297096@lists.php.net to get a copy of this message
Hello, 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: http://raxanpdi.com/downloads.html __ Raymond Irving --- On Sat, 8/22/09, Manuel Lemos <mlemos@acm.org> wrote: From: Manuel Lemos <mlemos@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" <phplists@hyphusonline.com> Cc: php-general@lists.php.net Date: Saturday, August 22, 2009, 1:07 AM Hello, 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. http://www.phpclasses.org/secure-html-filter -- Regards, Manuel Lemos Find and post PHP jobs http://www.phpclasses.org/jobs/ PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#297096) next »