evaluate will not return a boolean for a XPath expression that selects a node, you have to use:
$found = $xpath->evaluate("boolean(//span[contains(text(),'blablabla')])");
質問
I want to search specific text on a webpage using XPath.
<?php
$url = 'http://www.barringtonsports.com/browse/hockey_sticks/show/325/list';
$html = file_get_contents($url);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$found = $xpath->evaluate("//span[contains(text(),'blablabla')]");
if(!$found){
echo "NOT FOUND";
}
else{
echo "found";
}
?>
it always give the output found as the text blablabla is not in the webpage. where is the problem? Is my evalute expression correct for searching specific text?
解決
evaluate will not return a boolean for a XPath expression that selects a node, you have to use:
$found = $xpath->evaluate("boolean(//span[contains(text(),'blablabla')])");