How do I extract link text from anchor tag as well as the URL from
How do I extract link text from anchor tag as well as the URL from
am 16.08.2009 09:33:34 von chrysanhy
--000feae85bc7b31a2304713d4ef0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
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 , 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
--000feae85bc7b31a2304713d4ef0--
Re: How do I extract link text from anchor tag as well as the URL from the "href" attribut
am 16.08.2009 10:43:00 von Ralph Deffke
try
$link->nodeValue()
or
$link->getContent()
im not shure which one works on an image link which is indeed a child of
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" 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 , 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
Re: Re: How do I extract link text from anchor tag as well as
am 16.08.2009 15:59:28 von chrysanhy
--000feaf0162cca8adc047142b270
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
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 wrote:
>
> try
>
> $link->nodeValue()
>
> or
>
> $link->getContent()
>
> im not shure which one works on an image link which is indeed a child of
> 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" 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 , 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
>
>
--000feaf0162cca8adc047142b270--
Re: How do I extract link text from anchor tag as well as the URL from the "href" attribut
am 16.08.2009 16:35:40 von Ralph Deffke
did u try it something like this
foreach ($links as $link) {
$int_url_list[$i]["href"] = $link->getAttribute( 'href' );
$int_url_list[$i++]["linkText"] = $link->getContent( ); // nodeValue();
}
that should work
send ur code then please
ralph_deffke@yahoo,de
"chrysanhy" 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 , 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
Re: Re: How do I extract link text from anchor tag as well as the URL from the "href" attr
am 16.08.2009 17:02:58 von Ralph Deffke
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" 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
wrote:
>
> >
> > try
> >
> > $link->nodeValue()
> >
> > or
> >
> > $link->getContent()
> >
> > im not shure which one works on an image link which is indeed a child of
> > 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" 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 , 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
> >
> >
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: How do I extract link text from anchor tag as well as
am 16.08.2009 18:29:37 von chrysanhy
--00c09f92321fc384a3047144cb43
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
I pasted the code exactly as you have it, and I got the following:
*Fatal error*: Call to undefined method DOMElement::getContent()
I got the same thing with nodeValue().
On Sun, Aug 16, 2009 at 7:35 AM, Ralph Deffke wrote:
> did u try it something like this
>
> foreach ($links as $link) {
> $int_url_list[$i]["href"] = $link->getAttribute( 'href' );
> $int_url_list[$i++]["linkText"] = $link->getContent( ); // nodeValue();
> }
> that should work
>
> send ur code then please
> ralph_deffke@yahoo,de
>
>
> "chrysanhy" 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 , 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
>
>
--00c09f92321fc384a3047144cb43--
Re: Re: How do I extract link text from anchor tag as well as
am 16.08.2009 18:43:35 von chrysanhy
--00c09f99e549b682fa047144fd23
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
WHile waiting for suggestions for extracting the link text from the DOM, I
tried a brute force approach using the URLs I had found with getAttribute(),
but found myself baffled by my results. I boiled down my issue with this
approach to the following snippet.
$htmldata =<<
http://www.protools.com/users/user_story.cfm?story_id=1162&a mp;lang=1"> "Creating
Surround Mixes with Tim Weidner"
src="new.gif" width="28">
- Magnification engineer talks about mixing the album at
the
ProTools site, by Jim Batchco
http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html">"Don't
Go" Video
- Presented by Beyond
Music
(
Required)
EOB;
$url = 'http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html';
$posn = strpos($url, $htmldata);
echo "URL |$url| position is |$posn|";
Running this gives me:
URL |http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html| position is ||
I've tried lots of functions, and even regular expressions, but I cannot get
the code to find the URL in the HTML. While I still hope for a DOM solution
to getting this link text, WHY can't the code find the URL in the HTML
snippet?
On Sun, Aug 16, 2009 at 9:29 AM, chrysanhy wrote:
> I pasted the code exactly as you have it, and I got the following:
>
> *Fatal error*: Call to undefined method DOMElement::getContent()
>
> I got the same thing with nodeValue().
>
>
> On Sun, Aug 16, 2009 at 7:35 AM, Ralph Deffke wrote:
>
>> did u try it something like this
>>
>> foreach ($links as $link) {
>> $int_url_list[$i]["href"] = $link->getAttribute( 'href' );
>> $int_url_list[$i++]["linkText"] = $link->getContent( ); //
>> nodeValue();
>> }
>> that should work
>>
>> send ur code then please
>> ralph_deffke@yahoo,de
>>
>>
>> "chrysanhy" 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 , 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
>>
>>
>
--00c09f99e549b682fa047144fd23--
Re: Re: How do I extract link text from anchor tag as well as the URL from the "href" attr
am 16.08.2009 19:34:40 von Ralph Deffke
well the immage goes inside the
on ur html the node a has no value however u should not get a error
this is pergect jtml link
border="0" alt="THEMA">
ralph
"chrysanhy" wrote in message
news:88827b190908160943t2254137fve43771c7e4f8cc18@mail.gmail .com...
> WHile waiting for suggestions for extracting the link text from the DOM, I
> tried a brute force approach using the URLs I had found with
getAttribute(),
> but found myself baffled by my results. I boiled down my issue with this
> approach to the following snippet.
>
> $htmldata =<<
>
http://www.protools.com/users/user_story.cfm?story_id=1162&a mp;lang=1"> "Creating
>
> Surround Mixes with Tim Weidner"
> src="new.gif" width="28">
> - Magnification engineer talks about mixing the album
at
> the
> ProTools site, by Jim Batchco
> http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html">"Don't
> Go" Video
>
- Presented by
Beyond
> Music
> (
href="http://www.apple.com/quicktime/download/">QuickTime
>
> Required)
> EOB;
> $url = 'http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html';
> $posn = strpos($url, $htmldata);
> echo "URL |$url| position is |$posn|";
>
> Running this gives me:
>
> URL |http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html| position is
||
>
> I've tried lots of functions, and even regular expressions, but I cannot
get
> the code to find the URL in the HTML. While I still hope for a DOM
solution
> to getting this link text, WHY can't the code find the URL in the HTML
> snippet?
>
> On Sun, Aug 16, 2009 at 9:29 AM, chrysanhy
wrote:
>
> > I pasted the code exactly as you have it, and I got the following:
> >
> > *Fatal error*: Call to undefined method DOMElement::getContent()
> >
> > I got the same thing with nodeValue().
> >
> >
> > On Sun, Aug 16, 2009 at 7:35 AM, Ralph Deffke
wrote:
> >
> >> did u try it something like this
> >>
> >> foreach ($links as $link) {
> >> $int_url_list[$i]["href"] = $link->getAttribute( 'href' );
> >> $int_url_list[$i++]["linkText"] = $link->getContent( ); //
> >> nodeValue();
> >> }
> >> that should work
> >>
> >> send ur code then please
> >> ralph_deffke@yahoo,de
> >>
> >>
> >> "chrysanhy" 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 , 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
> >>
> >>
> >
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: How do I extract link text from anchor tag as well as the URL from the "href" attr
am 16.08.2009 20:26:08 von Ralph Deffke
this worked here:
$html = new DOMDocument();
$html->loadHtmlFile("testHtml.html");
$links = $html->getElementsByTagName('a');
echo "
";
foreach ($links as $item) {
echo $item->getAttribute( 'href' ). "\n";
echo "-------" . $item->nodeValue . "\n";
}
echo "
";
?>
Im sending u the 2 files directly in a minute. it came out, as I thought
earlier that u have to check if the tags has got children to extract
image links.
ralph_deffke@yahoo.de
"chrysanhy" wrote in message
news:88827b190908160943t2254137fve43771c7e4f8cc18@mail.gmail .com...
> WHile waiting for suggestions for extracting the link text from the DOM, I
> tried a brute force approach using the URLs I had found with
getAttribute(),
> but found myself baffled by my results. I boiled down my issue with this
> approach to the following snippet.
>
> $htmldata =<<
>
http://www.protools.com/users/user_story.cfm?story_id=1162&a mp;lang=1"> "Creating
>
> Surround Mixes with Tim Weidner"
> src="new.gif" width="28">
> - Magnification engineer talks about mixing the album
at
> the
> ProTools site, by Jim Batchco
> http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html">"Don't
> Go" Video
>
- Presented by
Beyond
> Music
> (
href="http://www.apple.com/quicktime/download/">QuickTime
>
> Required)
> EOB;
> $url = 'http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html';
> $posn = strpos($url, $htmldata);
> echo "URL |$url| position is |$posn|";
>
> Running this gives me:
>
> URL |http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html| position is
||
>
> I've tried lots of functions, and even regular expressions, but I cannot
get
> the code to find the URL in the HTML. While I still hope for a DOM
solution
> to getting this link text, WHY can't the code find the URL in the HTML
> snippet?
>
> On Sun, Aug 16, 2009 at 9:29 AM, chrysanhy
wrote:
>
> > I pasted the code exactly as you have it, and I got the following:
> >
> > *Fatal error*: Call to undefined method DOMElement::getContent()
> >
> > I got the same thing with nodeValue().
> >
> >
> > On Sun, Aug 16, 2009 at 7:35 AM, Ralph Deffke
wrote:
> >
> >> did u try it something like this
> >>
> >> foreach ($links as $link) {
> >> $int_url_list[$i]["href"] = $link->getAttribute( 'href' );
> >> $int_url_list[$i++]["linkText"] = $link->getContent( ); //
> >> nodeValue();
> >> }
> >> that should work
> >>
> >> send ur code then please
> >> ralph_deffke@yahoo,de
> >>
> >>
> >> "chrysanhy" 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 , 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
> >>
> >>
> >
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: How do I extract link text from anchor tag as well as
am 16.08.2009 22:23:43 von chrysanhy
--00c09f92321f031e0904714811b6
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
The code snippet below worked! Thank you so much for your time helping me
with this!
On Sun, Aug 16, 2009 at 11:26 AM, Ralph Deffke wrote:
> this worked here:
>
>
> $html = new DOMDocument();
> $html->loadHtmlFile("testHtml.html");
> $links = $html->getElementsByTagName('a');
> echo "";
>
> foreach ($links as $item) {
> echo $item->getAttribute( 'href' ). "\n";
> echo "-------" . $item->nodeValue . "\n";
> }
>
> echo "
";
>
> ?>
>
> Im sending u the 2 files directly in a minute. it came out, as I thought
> earlier that u have to check if the tags has got children to extract
> image links.
>
> ralph_deffke@yahoo.de
>
>
> "chrysanhy" wrote in message
> news:88827b190908160943t2254137fve43771c7e4f8cc18@mail.gmail .com...
> > WHile waiting for suggestions for extracting the link text from the DOM,
> I
> > tried a brute force approach using the URLs I had found with
> getAttribute(),
> > but found myself baffled by my results. I boiled down my issue with this
> > approach to the following snippet.
> >
> > $htmldata =<<
> >
> http://www.protools.com/users/user_story.cfm?story_id=1162&a mp;lang=1
> ">"Creating
> >
> > Surround Mixes with Tim Weidner"
> > src="new.gif" width="28">
> > - Magnification engineer talks about mixing the album
> at
> > the
> > ProTools site, by Jim Batchco
> > http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html">"Don't
> > Go" Video
> >
- Presented by
> Beyond
> > Music
> > (
> href="http://www.apple.com/quicktime/download/">QuickTime
> >
> > Required)
> > EOB;
> > $url = 'http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html';
> > $posn = strpos($url, $htmldata);
> > echo "URL |$url| position is |$posn|";
> >
> > Running this gives me:
> >
> > URL |http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html|position is
> ||
> >
> > I've tried lots of functions, and even regular expressions, but I cannot
> get
> > the code to find the URL in the HTML. While I still hope for a DOM
> solution
> > to getting this link text, WHY can't the code find the URL in the HTML
> > snippet?
> >
> > On Sun, Aug 16, 2009 at 9:29 AM, chrysanhy
> wrote:
> >
> > > I pasted the code exactly as you have it, and I got the following:
> > >
> > > *Fatal error*: Call to undefined method DOMElement::getContent()
> > >
> > > I got the same thing with nodeValue().
> > >
> > >
> > > On Sun, Aug 16, 2009 at 7:35 AM, Ralph Deffke
> wrote:
> > >
> > >> did u try it something like this
> > >>
> > >> foreach ($links as $link) {
> > >> $int_url_list[$i]["href"] = $link->getAttribute( 'href' );
> > >> $int_url_list[$i++]["linkText"] = $link->getContent( ); //
> > >> nodeValue();
> > >> }
> > >> that should work
> > >>
> > >> send ur code then please
> > >> ralph_deffke@yahoo,de
> > >>
> > >>
> > >> "chrysanhy" 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 , 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
> > >>
> > >>
> > >
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--00c09f92321f031e0904714811b6--
Re: How do I extract link text from anchor tag as well as the URLfrom the "href" attribute
am 22.08.2009 07:07:46 von Manuel Lemos
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 , 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
Re: Re: How do I extract link text from anchor tag as well as the URL from the "href" attr
am 23.08.2009 04:56:41 von Raymond Irving
--0-1049319535-1250996201=:18174
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Hello,
You might also want to try using the Raxan framework:
require_once 'raxan/pdi/gateway.php';
$page =3D new RichWebPage('page.html');
echo $page['a']->text(); // this will get the text betwen the a tag
=A0
To get the image element use:
$elm =3D $page['a img']->node(0);
You can download Raxan here:
http://raxanpdi.com/downloads.html
__
Raymond Irving
--- On Sat, 8/22/09, Manuel Lemos wrote:
From: Manuel Lemos
Subject: [PHP] Re: How do I extract link text from anchor tag as well as th=
e URL from the "href" attribute
To: "chrysanhy"
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:
>=20
> $html =3D new DOMDocument();
> $htmlpage->loadHtmlFile($location);
> $xpath =3D new DOMXPath($htmlpage);
> $links =3D $xpath->query( '//a' );
> foreach ($links as $link)
> { $int_url_list[$i++] =3D $link->getAttribute( 'href' ) . "\n"; }
>=20
> If I have a link , 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=A0 that does exactly
what you ask.
http://www.phpclasses.org/secure-html-filter
--=20
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/
--=20
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--0-1049319535-1250996201=:18174--