3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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->getChildNodes() 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){ $before = mb_substr($node->textContent, 0, $o); $wrap = mb_substr($node->textContent, $o, mb_strlen($searchString, "UTF-8")); $after = mb_substr($node->textContent, $o); print_r($before); print_r($wrap); print_r($after); } } } } }; foreach($words as $name => $word) $ps($container->documentNode, $word, $name); } $x = new DOMDocument(); $x->loadXML("<data>drugs cartel</data>"); applyHLToSiblings($x);
based on PUOts
Output for 7.2.0
Notice: Undefined variable: container in /in/24cAU on line 36 Notice: Trying to get property 'documentNode' of non-object in /in/24cAU on line 36 Fatal error: Uncaught Error: Call to a member function getChildNodes() on null in /in/24cAU:17 Stack trace: #0 /in/24cAU(36): {closure}(NULL, 'cart', 0) #1 /in/24cAU(44): applyHLToSiblings(Object(DOMDocument)) #2 {main} thrown in /in/24cAU on line 17
Process exited with code 255.
Output for 7.0.0 - 7.1.10
Notice: Undefined variable: container in /in/24cAU on line 36 Notice: Trying to get property of non-object in /in/24cAU on line 36 Fatal error: Uncaught Error: Call to a member function getChildNodes() on null in /in/24cAU:17 Stack trace: #0 /in/24cAU(36): {closure}(NULL, 'cart', 0) #1 /in/24cAU(44): applyHLToSiblings(Object(DOMDocument)) #2 {main} thrown in /in/24cAU on line 17
Process exited with code 255.
Output for 5.6.8 - 5.6.28
Notice: Undefined variable: container in /in/24cAU on line 36 Notice: Trying to get property of non-object in /in/24cAU on line 36 Fatal error: Call to a member function getChildNodes() on null in /in/24cAU on line 17
Process exited with code 255.
Output for 5.3.19 - 5.5.35
Notice: Undefined variable: container in /in/24cAU on line 36 Notice: Trying to get property of non-object in /in/24cAU on line 36 Fatal error: Call to a member function getChildNodes() on a non-object in /in/24cAU on line 17
Process exited with code 255.