php - Empty XPath result when it shouldn't be -
i have following simple html:
<span class="myclass"> <strong>number</strong> : 9 </span>
i want parse return: : 9
i'm trying following xpath i'm pretty sure correct i'm not getting text returned:
$dom = new domdocument(); $dom->loadhtml($htmlasabove); $xpath = new domxpath($dom); $result = $xpath->query("normalize-space(//span/text()[last()])"); if($result->length > 0) { echo 'here '.$result->item(0); } else { echo 'nothing'; // returns every time }
nothing wrong xpath, domxpath::query()
unable return other node-set. executing xpath expression doesn't return node-set*, use domxpath::evaluate()
instead :
$result = $xpath->evaluate("normalize-space(//span/text()[last()])"); echo 'here '.$result;
*: xpath normalize-space()
function returns string
output :
here : 9
Comments
Post a Comment