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); $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.0090.00618.93
8.3.50.0330.01322.33
8.3.40.0120.00419.54
8.3.30.0080.00819.45
8.3.20.0040.00422.40
8.3.10.0030.00621.33
8.3.00.0160.00322.34
8.2.180.0090.00619.04
8.2.170.0110.01122.96
8.2.160.0110.00422.62
8.2.150.0060.00324.18
8.2.140.0040.00724.66
8.2.130.0090.00020.08
8.2.120.0050.00326.35
8.2.110.0100.00021.69
8.2.100.0070.00718.53
8.2.90.0030.00518.53
8.2.80.0000.00819.61
8.2.70.0060.00318.38
8.2.60.0030.00518.53
8.2.50.0050.00518.25
8.2.40.0000.00820.91
8.2.30.0070.00419.74
8.2.20.0040.00418.52
8.2.10.0000.00818.64
8.2.00.0040.00418.15
8.1.280.0150.00325.92
8.1.270.0000.00823.99
8.1.260.0060.00326.35
8.1.250.0040.00428.09
8.1.240.0030.00621.84
8.1.230.0070.00421.45
8.1.220.0080.00018.29
8.1.210.0080.00019.30
8.1.200.0090.00317.85
8.1.190.0030.00617.85
8.1.180.0000.00818.10
8.1.170.0000.01019.21
8.1.160.0040.00419.57
8.1.150.0040.00422.56
8.1.140.0040.00419.99
8.1.130.0000.00719.43
8.1.120.0000.00718.02
8.1.110.0060.00318.06
8.1.100.0000.00818.11
8.1.90.0080.00018.05
8.1.80.0040.00417.95
8.1.70.0000.00718.00
8.1.60.0000.00818.18
8.1.50.0030.00618.09
8.1.40.0030.00618.11
8.1.30.0000.00818.05
8.1.20.0000.00918.25
8.1.10.0040.00418.25
8.1.00.0040.00418.00
8.0.300.0000.00820.42
8.0.290.0050.00317.38
8.0.280.0040.00418.76
8.0.270.0000.00817.73
8.0.260.0000.00717.80
8.0.250.0040.00417.48
8.0.240.0040.00417.51
8.0.230.0050.00317.48
8.0.220.0060.00317.56
8.0.210.0070.00017.53
8.0.200.0030.00317.49
8.0.190.0050.00517.61
8.0.180.0030.00617.45
8.0.170.0030.00517.54
8.0.160.0070.00017.57
8.0.150.0070.00017.45
8.0.140.0070.00317.34
8.0.130.0030.00313.97
8.0.120.0040.00417.41
8.0.110.0040.00417.41
8.0.100.0030.00617.50
8.0.90.0000.00817.57
8.0.80.0090.00617.38
8.0.70.0050.00317.43
8.0.60.0000.00817.54
8.0.50.0040.00417.46
8.0.30.0100.00917.58
8.0.20.0090.01117.74
8.0.10.0040.00417.70
8.0.00.0110.00717.37
7.4.330.0030.00315.65
7.4.320.0030.00317.15
7.4.300.0000.00817.27
7.4.290.0030.00317.21
7.4.280.0050.00517.09
7.4.270.0000.00717.15
7.4.260.0080.00017.09
7.4.250.0040.00417.20
7.4.240.0000.00717.18
7.4.230.0040.00417.26
7.4.220.0110.00617.06
7.4.210.0100.01117.15
7.4.200.0080.00017.36
7.4.160.0090.00617.14
7.4.150.0030.01517.40
7.4.140.0080.01117.86
7.4.130.0130.01117.20
7.4.120.0090.00817.03
7.4.110.0090.00917.27
7.4.100.0140.00416.95
7.4.90.0150.00316.98
7.4.80.0100.01319.39
7.4.70.0060.01017.13
7.4.60.0090.00917.30
7.4.50.0030.00817.09
7.4.40.0070.01017.00
7.4.30.0050.01417.29
7.4.00.0000.01915.28
7.3.330.0070.00013.63
7.3.320.0050.00013.75
7.3.310.0060.00316.86
7.3.300.0000.00716.73
7.3.290.0080.00016.88
7.3.280.0080.01216.87
7.3.270.0140.00417.40
7.3.260.0120.00916.89
7.3.250.0100.01116.99
7.3.240.0090.00917.09
7.3.230.0100.00717.14
7.3.210.0090.00917.19
7.3.200.0100.00716.88
7.3.190.0100.00717.13
7.3.180.0100.01316.84
7.3.170.0090.00816.88
7.3.160.0110.00717.05
7.3.10.0140.00316.64
7.3.00.0110.01116.77
7.2.330.0070.01117.39
7.2.320.0090.00917.38
7.2.310.0070.01017.16
7.2.300.0120.01217.30
7.2.290.0130.01017.20
7.2.130.0090.00717.29
7.2.120.0140.00417.12
7.2.110.0000.01517.25
7.2.100.0100.00617.21
7.2.90.0090.01217.21
7.2.80.0030.01616.97
7.2.70.0060.00617.22
7.2.60.0140.00516.96
7.2.50.0060.00917.34
7.2.40.0040.01117.22
7.2.30.0030.01017.23
7.2.20.0000.01517.11
7.2.10.0060.00617.24
7.2.00.0040.01118.48
7.1.250.0030.01115.68
7.1.200.0300.00015.76
7.1.100.0060.00618.11
7.1.70.0030.00617.60
7.1.60.0080.00417.35
7.1.10.0130.05722.42
7.1.00.0100.05722.64
7.0.200.0110.00717.20
7.0.150.0030.07021.96
7.0.140.0070.06021.93
7.0.130.0100.05321.96
7.0.120.0100.05322.02
7.0.110.0030.06321.95
7.0.100.0030.06322.03
7.0.90.0130.05321.99
7.0.80.0130.05022.24
7.0.70.0100.05322.05
7.0.60.0030.06021.79
7.0.50.0170.04722.10
7.0.40.0130.05022.09
7.0.30.0030.06022.00
7.0.20.0030.06022.05
7.0.10.0100.05322.08
7.0.00.0100.05022.03

preferences:
45.45 ms | 401 KiB | 5 Q