I'm an xPath and PHP newbie. I want to extract the attribute values from a tag
<a onclick="sell_this_form('24042', '195'); return false;" href="javascript:void(0);">Sell</a>
I want to extract the first argument to sell_this_form ie 24042. I've built an expression that ends this way
.../a/@onclick
It evaluates properly on my Xpath expression builder. However when I dump my result in PHP using var_dump(), I get a blank node. How can I get it to give me what I need? I've tried
$xpath->query("//input[@name]/@name")->value;
as suggested on this site. However, I get an error. What am I doing wrong? Relevant sections of my code follow
$dom = new DOMDocument;
$prev_err = libxml_use_internal_errors(TRUE);
$dom->loadHTML($page);
libxml_clear_errors();
libxml_use_internal_errors($prev_err);
$xpath = new DOMXPath($dom);
$entries = $xpath->query($xpathExpr);
//$entries = $xpath->query($xpathExpr)->value;
if (!$entries)
throw new Exception("XPath evaluation error");
foreach ($entries as $entry)
echo "<br/>value: {$entry->nodeValue}";