PHP Classes

Problem related to DOMDocument

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  Problem related to DOMDocument  
Subject:Problem related to DOMDocument
Summary:Unable to access raw string between <a> and </a>
Messages:3
Author:pankaj shukla
Date:2009-02-10 13:19:34
Update:2009-02-16 18:47:12
 

  1. Problem related to DOMDocument   Reply   Report abuse  
Picture of pankaj shukla pankaj shukla - 2009-02-10 16:58:43
I am trying to extract all the links ("a" tags) and storing href and anchor text(raw text between the <a> and </a> tags) into Database.

I am having no problem doing this until the contents are an image.

HTML file contains code like following line in many places -
<a href="http://example.com"><img src="example.gif"></a>

My code o
I am using DOM objects but unable to access it.

My code is like -

--------------------
$dom = new DOMDocument();
@$dom->loadHTML($input);
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("//a");//get all a tags
for ($i = 0; $i < $hrefs->length; $i++)
{
$href = $hrefs->item($i);
$links['link'][$i]=$href->getAttribute('href');
$links['text'][$i]=$href->nodeValue;
}
$dom->save('test.html');

--------------------

If anyone has any idea/suggestion, please share it...

Thanks in advance
- Pankaj

There are 2 replies in this thread, which are not being displayed.
Browsing this forum thread replies is available only to premium subscribers.


Go to the premium subscriptions page to learn how to become a premium subscriber and have full access to this forum.