Hi,
I am using DOMDocument functionality of PHP for accessing <a> tags in a HTML as I am going to store "href" and "content" (raw string between <a> and </a>).
I am getting right things until getting <img> tag as content.
like
<a href="http://www.example.com"><img src="http://www.example.com/tex.gif" /></a>
I want to have anything between <a> and </a>.
My Code is :-
$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 have any idea then please share it.
Thanks
- Pankaj