@ 2015-11-14T22:23:07Z <?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";
*/
$mt = function($content) use($D){
return $D->createTextNode($content);
};
$ms = function($name, $content = null) use($D){
$span = $D->createElement("span");
$span->setAttribute("class", "word$name");
$content !== null ? $span->appendChild($content) : null;
return $span;
};
$ps = function($siblingsContainer, $searchString, $name) use($D, $ms, $mt){
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);
$before = $ms($name, $wrap);
$newSpan->textContent = $wrap;
$before ? $node->insertBefore($node->nextSibling, $mt($before));
$node->insertBefore($node->nextSibling, $ms($mt($wrap), $name));
$after ? $node->insertBefore($node->nextSibling, $mt($after));
}
}
}
}
};
foreach($words as $name => $word)
$ps($D->documentElement, $word, $name);
}
$x = new DOMDocument();
$x->loadXML("<data>drugs cartel</data>");
applyHLToSiblings($x);
var_dump($x->saveXML());
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.6.15 0.003 0.057 18.18 5.6.14 0.007 0.043 18.21 5.6.13 0.003 0.077 18.15 5.6.12 0.003 0.057 21.17 5.6.11 0.010 0.073 21.04 5.6.10 0.013 0.060 20.99 5.6.9 0.020 0.067 21.00 5.6.8 0.007 0.037 20.43 5.5.30 0.003 0.047 17.99 5.5.29 0.010 0.077 18.06 5.5.28 0.013 0.093 20.70 5.5.27 0.000 0.050 20.88 5.5.26 0.007 0.083 20.96 5.5.25 0.007 0.043 20.59 5.5.24 0.027 0.070 20.18
preferences:dark mode live preview
141.84 ms | 1394 KiB | 7 Q