3v4l.org

run code in 300+ PHP versions simultaneously
<?php $desc = '<p> <span style="font-size:12pt;"><strong>Nappe bouton power Samsung Galaxy S6 Edge G925F</strong></span> <br> <span style="font-size:12pt;"><u><i title="bouton power">Nappe Bouton poweR, compatible Samsung Galaxy S6 Edge G925F.</i></u></span> </p>'; canLinkThisWordIn('bouton Power', $desc); function canLinkThisWordIn($word, $html){ $forbidenTagsArray = array('strong', 'a', 'b', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'); $dom = new DOMDocument(); $dom->loadHTML($html); $xpath = new DOMXpath($dom); $wordTags = $xpath->query("//*[text()[contains(translate(., '".strtoupper($word)."', '".strtolower($word)."'), '".strtolower($word)."')]]"); foreach($wordTags as $wordTag){ if(checkTagAndParent($wordTag, $forbidenTagsArray)){ echo "\n".$wordTag->nodeName." == ".$wordTag->nodeValue; } } return false; } function checkTagAndParent($tag, $forbiden){ if(!in_array($tag->tagName, $forbiden)){ if($tag->parentNode){ $parentTags = array_filter(explode("/", preg_replace("/\[[^]]+\]/", "", $tag->getNodePath()))); foreach($parentTags as $parentTag){ if(in_array($parentTag, $forbiden)){ return false; } } } return true; } return false; }
Output for 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 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.4, 8.3.6
i == Nappe Bouton poweR, compatible Samsung Galaxy S6 Edge G925F.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 i == Nappe Bouton poweR, compatible Samsung Galaxy S6 Edge G925F.

preferences:
231.51 ms | 402 KiB | 245 Q