3v4l.org

run code in 300+ PHP versions simultaneously
<?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());

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).

VersionSystem time (s)User time (s)Memory (MiB)
5.6.150.0030.05718.18
5.6.140.0070.04318.21
5.6.130.0030.07718.15
5.6.120.0030.05721.17
5.6.110.0100.07321.04
5.6.100.0130.06020.99
5.6.90.0200.06721.00
5.6.80.0070.03720.43
5.5.300.0030.04717.99
5.5.290.0100.07718.06
5.5.280.0130.09320.70
5.5.270.0000.05020.88
5.5.260.0070.08320.96
5.5.250.0070.04320.59
5.5.240.0270.07020.18

preferences:
141.84 ms | 1394 KiB | 7 Q