Thursday, 29 August 2013

Xpath query assistance nested anchor href extract

Xpath query assistance nested anchor href extract

Here is my code:
$text = '<div class="cgus_post"><a href="?p=15055">Hello</a></div>';
$dom = new DomDocument();
$dom->loadHTML($text);
$classname = 'cgus_post';
$finder = new DomXPath($dom);
$nodes = $finder->query('//div[class="cgus_post"]//@href');
I'm trying to get the href text for an anchor link within the div
cgus_post. What's wrong with my query?

No comments:

Post a Comment