3v4l.org

run code in 300+ PHP versions simultaneously
<?php $desc = '<p> <strong>Nappe bouton power</strong><br> <u class="uuu"><i title="a bouton power b">Nappe bouton power, compatible Samsung Galaxy S6 Edge G925F.</i></u> </p>'; echo canLinkThisWordIn('bouton power', $desc, true); function canLinkThisWordIn($word, $html, $linkIt){ $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)){ if($linkIt){ //$newWordTagValue = ''; //$wordTag->nodeValue = ''; //$wordTag->appendChild($dom->createTextNode($titleText)); //$replacement = $dom->createDocumentFragment(); //$replacement->appendChild($newWordTag); $sensitiveWord = $word; $newWordTagLink = '<a href="#" title="#" class="internalink"><b>'.$sensitiveWord.'</b></a>'; $newWordTagHtml = str_ireplace($sensitiveWord, $newWordTagLink, getNodeInnerHTML($wordTag)); $helper = new DOMDocument(); $helper->loadHTML($newWordTagHtml); $newWordTag = $dom->createElement('b'); $newWordTag->appendChild($dom->importNode($helper->documentElement, true)); // save to dom $wordTag->parentNode->replaceChild($newWordTag, $wordTag); $body = $dom->getElementsByTagName('body'); $body = $body->item(0)->item(0); $newHTML = $dom->saveHTML($body); return $newHTML; $newHTML = $dom->saveHTML(); $newHTML = str_ireplace(array('<html>', '</html>', '<body><p>', '</p></body>'), '', $newHTML); return '<p>'.$newHTML.'</p>'; } return true; } } 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; } function getNodeInnerHTML(DOMNode $element){ $innerHTML = ""; $children = $element->childNodes; foreach($children as $child){ $innerHTML .= $element->ownerDocument->saveHTML($child); } return $innerHTML; } function getNodeOuterHTML($e){ $doc = new DOMDocument(); $doc->appendChild($doc->importNode($e, true)); return $doc->saveHTML(); }

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)
8.3.60.0110.00419.31
8.3.50.0130.00823.17
8.3.40.0100.01019.85
8.3.30.0140.00719.59
8.3.20.0060.01022.35
8.3.10.0000.00821.41
8.3.00.0110.00722.41
8.2.180.0060.00919.04
8.2.170.0080.00822.96
8.2.160.0050.01022.62
8.2.150.0150.00424.18
8.2.140.0080.00824.66
8.2.130.0060.00320.08
8.2.120.0060.00326.35
8.2.110.0040.01221.54
8.2.100.0060.00618.36
8.2.90.0030.00519.66
8.2.80.0030.00618.25
8.2.70.0030.00518.25
8.2.60.0030.00518.55
8.2.50.0030.00518.50
8.2.40.0030.00520.96
8.2.30.0060.00319.75
8.2.20.0040.00418.49
8.2.10.0030.00518.61
8.2.00.0050.00318.26
8.1.280.0130.01325.92
8.1.270.0070.00321.32
8.1.260.0060.00326.35
8.1.250.0000.00928.09
8.1.240.0100.00023.27
8.1.230.0070.00418.26
8.1.220.0050.00518.26
8.1.210.0060.00318.77
8.1.200.0030.00617.98
8.1.190.0000.00817.63
8.1.180.0000.00818.10
8.1.170.0060.00319.09
8.1.160.0040.00419.32
8.1.150.0040.00422.39
8.1.140.0000.00820.00
8.1.130.0020.00519.45
8.1.120.0040.00417.97
8.1.110.0000.00918.05
8.1.100.0080.00018.01
8.1.90.0000.00817.94
8.1.80.0040.00418.11
8.1.70.0000.00718.02
8.1.60.0030.00518.15
8.1.50.0040.00417.97
8.1.40.0030.00618.10
8.1.30.0000.00818.09
8.1.20.0040.00418.25
8.1.10.0080.00018.13
8.1.00.0030.00518.17
8.0.300.0000.00918.77
8.0.290.0030.00617.25
8.0.280.0030.00318.93
8.0.270.0000.00717.69
8.0.260.0030.00317.78
8.0.250.0040.00417.52
8.0.240.0040.00417.51
8.0.230.0030.00617.60
8.0.220.0050.00517.57
8.0.210.0070.00017.59
8.0.200.0000.00717.48
8.0.190.0100.00017.57
8.0.180.0040.00417.54
8.0.170.0080.00017.44
8.0.160.0040.00417.46
8.0.150.0000.00917.40
8.0.140.0000.01117.43
8.0.130.0000.00614.11
8.0.120.0000.00817.41
8.0.110.0070.00017.57
8.0.100.0030.00517.44
8.0.90.0050.00317.54
8.0.80.0070.01317.47
8.0.70.0000.00817.23
8.0.60.0040.00417.35
8.0.50.0000.00817.58
8.0.30.0080.01217.70
8.0.20.0100.00917.81
8.0.10.0070.00017.53
8.0.00.0140.01117.29
7.4.330.0060.00015.55
7.4.320.0000.00717.11
7.4.300.0060.00017.20
7.4.290.0000.00717.01
7.4.280.0040.00417.19
7.4.270.0030.00617.03
7.4.260.0040.00417.12
7.4.250.0000.00817.17
7.4.240.0040.00417.19
7.4.230.0000.00717.25
7.4.220.0110.00917.21
7.4.210.0080.01017.12
7.4.200.0030.00617.25
7.4.160.0120.00417.11
7.4.150.0100.01017.40
7.4.140.0110.00917.86
7.4.130.0100.01117.14
7.4.120.0060.01217.19
7.4.110.0090.01117.06
7.4.100.0100.01717.18
7.4.90.0070.01317.35
7.4.80.0090.00919.39
7.4.70.0100.00717.23
7.4.60.0030.01417.27
7.4.50.0070.01016.97
7.4.40.0160.00317.29
7.4.30.0110.00517.13
7.4.00.0060.00915.49
7.3.330.0050.00013.84
7.3.320.0000.00613.91
7.3.310.0030.00316.81
7.3.300.0030.00316.84
7.3.290.0000.00716.93
7.3.280.0090.00916.94
7.3.270.0140.00317.40
7.3.260.0160.00617.05
7.3.250.0110.00817.04
7.3.240.0150.00417.07
7.3.230.0070.01716.98
7.3.210.0060.01316.84
7.3.200.0100.00716.96
7.3.190.0090.00917.17
7.3.180.0180.00416.91
7.3.170.0140.00417.10
7.3.160.0100.00717.08
7.2.330.0090.00917.40
7.2.320.0070.01017.20
7.2.310.0100.01017.36
7.2.300.0120.00617.13
7.2.290.0180.00417.16
7.2.60.0060.00617.43
7.2.00.0030.00619.96
7.1.200.0040.01116.13
7.1.100.0000.01018.56
7.1.70.0020.00517.63
7.1.60.0100.00317.41
7.1.50.0180.01435.31
7.1.10.0130.05722.35
7.1.00.0130.05322.52
7.0.200.0000.01717.21
7.0.150.0170.05022.05
7.0.140.0070.05321.95
7.0.130.0070.05722.23
7.0.120.0070.05721.98
7.0.110.0130.05322.01
7.0.100.0030.05721.95
7.0.90.0070.08021.99
7.0.80.0100.05321.95
7.0.70.0130.05722.24
7.0.60.0000.06022.05
7.0.50.0000.06022.04
7.0.40.0070.06022.00
7.0.30.0070.05722.03
7.0.20.0130.05021.94
7.0.10.0100.05021.97
7.0.00.0030.06022.02

preferences:
58.58 ms | 401 KiB | 5 Q