Re: Re: 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]

 



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@xxxxxxx> wrote:

From: Manuel Lemos <mlemos@xxxxxxx>
Subject:  Re: How do I extract link text from anchor tag as well as the URL from the "href" attribute
To: "chrysanhy" <phplists@xxxxxxxxxxxxxxxx>
Cc: php-general@xxxxxxxxxxxxx
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


[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