I would like to get the node of an element containing a given text in the node
I tried this
$template = file_get_contents($file);
// search for the query get_query_var( 's' )
if (stripos($template, get_query_var( 's' )) !== false) {
$html_content = str_get_html($template); // using simple_html_dom_parser
if($html_content->find('div.row', 0)){
$content = $html_content->find('div.row', 0)->innertext;
print findtext($content, $words);
}
}
And function findtext
function findtext($text,$word){
libxml_use_internal_errors(true);
//var_dump($text);
$dom = new DomDocument();
/* Load the HTML */
$dom->loadHTML($text);
/* Create a new XPath object */
$xp = new DomXPath($dom);
$result = $xp->query("//*[text()[contains(., '$text')]]");
var_dump($result);
}
I got this error DOMXPath#4008 (1) { public $document => string(22) "(object value omitted)" }
HTML example
<p class="smallerText blackB">
<b class="">Le COMIDENT est</b> également et particulièrement,
le <b class="">partenaire de l’Association Dentaire Fran?aise (ADF)</b>
avec qui il co-organise, en étroite collaboration chaque année,
l’Exposition du Congrès annuel au Palais des Congrès, qui regroupe
environ 400 exposants répartis sur 4 niveaux.
</p>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…