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

From: Date: Sun, 16 Aug 2009 15:02:58 +0000
Subject: Re: Re: How do I extract link text from anchor tag as well as the URL from the "href" attribute
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-296840@lists.php.net to get a copy of this message
I found this iteration over the item collection for ($i = 0; $i < $items->length; $i++) { echo $items->item($i)->nodeValue . "\n"; } check here as well http://us.php.net/manual/en/domnodelist.item.php doesn't seem a simple foreach dos it ralph_deffke@yahoo.de "chrysanhy" <phplists@hyphusonline.com> wrote in message news:88827b190908160659jada3a61ke43035e27f9a526e@mail.gmail.com... > It did not work. Both gave me a "Call to undefined method" fatal error. > > On Sun, Aug 16, 2009 at 1:43 AM, Ralph Deffke <ralph_deffke@yahoo.de> wrote: > > > > > try > > > > $link->nodeValue() > > > > or > > > > $link->getContent() > > > > im not shure which one works on an image link which is indeed a child of <a > > so u could also check if the node has a child, if so its an image with, in > > good practice. an alt attribute to use > > > > haven't tried but should work. let me know pls > > > > ralph_deffke@yahoo.de > > > > > > "chrysanhy" <phplists@hyphusonline.com> wrote in message > > > > news:88827b190908160033n226b370bqe2ab70732811b27@mail.gmail.com... > > > 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 > > > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > >

« previous php.general (#296840) next »