-1

I have the following html

<div class="logo"><a href="/">***® text.<sup>TM</sup></a></div>

I would like to get the value of href with php dom xpath, how would I accomplish that?

This is what I have tried:

$anchors = $domXpath->query("//div[@class='logo']/a");
foreach($anchors as $a)
{ 
    print $a->nodeValue." - ".$a->getAttribute("href")."<br/>";
}
unixmiah
  • 3,081
  • 1
  • 12
  • 26

1 Answers1

0

Here is the solution.

$xpath = new DOMXpath($dom);
$link = $xpath->query('//div[@class="logo"]/a');
$link->getAttribute('href')
supputuri
  • 13,644
  • 2
  • 21
  • 39