<?php
function applyHLToSiblings(DOMDocument $D){
$words[0] = "cart";
/*
$words[1] = "car";
$words[2] = "cartel";
$words[3] = "art";
$words[4] = "drug";
$words[5] = "drugs";
$words[6] = "rug";
$words[7] = "rugs";
*/
$ps = function($siblingsContainer, $searchString, $name) use($D){
foreach($siblingsContainer->childNodes as $node){
if($node instanceof DOMText){
if(mb_strlen($node->textContent, "UTF-8") >= mb_strlen($searchString)){
$o = mb_strpos($node->textContent, $searchString);
if($o !== false){
$l = mb_strlen($searchString, "UTF-8");
$before = mb_substr($node->textContent, 0, $o);
$wrap = mb_substr($node->textContent, $o, $l);
$after = mb_substr($node->textContent, $o + $l);
var_dump($before);
var_dump($wrap);
var_dump($after);
}
}
}
}
};
foreach($words as $name => $word)
$ps($D->documentElement, $word, $name);
}
$x = new DOMDocument();
$x->loadXML("<data>drugs cartel</data>");
applyHLToSiblings($x);
- Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- string(6) "drugs "
string(4) "cart"
string(2) "el"
preferences:
163.78 ms | 404 KiB | 182 Q