I have an XPath like this. I am trying to do exact match a string in the HTML.
$d->loadHTML('<?xml encoding="UTF-8">'.$html);
$xpath = new DOMXPath($d);
$txt="rest";
$txt=' '.$txt.' ';
$txt1=strtolower($txt);
$xpath->query('/html/body//text()['.
'contains('.
'translate(.,"'.strtoupper($txt).'","'.$txt1.'"),'.
'"'.$txt1.'")'.
']'.'[not(ancestor::a)][not(ancestor::h2)][not(ancestor::h3)]');
It is working if the string is like this.
"Please rest in ...."
But if
is present before 'rest' in the string rather than whitespace then it is not working.
"Please rest in ...."