3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyParser { private $domdoc; public function __construct(DOMDocument $domdoc){ $this->domdoc = $domdoc; } public function __toString() { return $this->domdoc->saveHTML(); } protected function replaceVariableInside($varName, $text, $idType, $idValue) { $nodes = $this->getNodes($idType, $idValue); $newTextNode = $this->getNodeFromText($text); array_map(function($node) use ($varName, $newTextNode){ /* @var $node DOMNode */ $textNodes = array_filter($node->childNodes, function($node){ return $node->nodeType === XML_TEXT_NODE; }); foreach ($textNodes as $textNode) { /* @var $textNode \DOMText */ $pos = strpos($textNode->nodeValue, $varName); if($pos !== false) { $newNode = $textNode->splitText($pos); $newNode->nodeValue = substr($newNode->nodeValue, strlen($varName)); $newNode->insertBefore($newTextNode); } } }, $nodes); } protected function getNodes($idType, $idValue) { switch ($idType){ case 'id': return [ $this->domdoc->getElementById($idValue) ]; break; case 'class': return (new DOMXPath($this->domdoc)) ->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $idValue ')]"); break; default: break; } } protected function insertInto($idType, $id, $text) { $newnode = $this->getNodeFromText($text); array_map(function($elementOfDom) use ($newnode){ /* @var $elementOfDom DOMNode */ @$elementOfDom->appendChild($newnode); }, $this->getNodes($idType, $id)); } protected function getNodeFromText($text) { $text = html_entity_decode($text); try { $tmp = new DOMDocument; $textDocumentRes = @$tmp->loadHTML('<?xml encoding="utf-8" ?><span>'.$text.'</span>'); } catch(Exception $e) { $textDocumentRes = false; } if($textDocumentRes) { $newnode = $this->domdoc->importNode($tmp->documentElement->firstChild->firstChild, true); } else { $newnode = $this->domdoc->createTextNode($text); $newnode->nodeValue = $text; } return $newnode; } } $domdocu = new DomDocument(); $domdocu->loadHTML(' <html> <head> </head> <body> <div id="first"> %ELEMENT% </div> <div class="second"> %ELEMENT% <div class="third"> %ELEMENT% </div> </div> <div class="fourth"> %ELEMENT% </div> </body> </html> '); $parser = new MyParser();

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.40.0150.00019.04
8.3.30.0070.01119.07
8.3.20.0060.00320.55
8.3.10.0000.00823.61
8.3.00.0060.00319.81
8.2.170.0070.00722.96
8.2.160.0060.00919.41
8.2.150.0030.00624.18
8.2.140.0040.00424.66
8.2.130.0060.00319.58
8.2.120.0000.00826.35
8.2.110.0070.00421.41
8.2.100.0120.00018.28
8.2.90.0080.00018.28
8.2.80.0040.00419.67
8.2.70.0050.00318.00
8.2.60.0000.01018.30
8.2.50.0060.00318.18
8.2.40.0030.00620.81
8.2.30.0050.00321.22
8.2.20.0000.00818.27
8.2.10.0030.00518.23
8.2.00.0060.00318.27
8.1.270.0040.00424.09
8.1.260.0030.00526.35
8.1.250.0070.00028.09
8.1.240.0000.00921.18
8.1.230.0080.00321.34
8.1.220.0060.00318.03
8.1.210.0080.00019.28
8.1.200.0090.00017.85
8.1.190.0080.00017.73
8.1.180.0040.00418.10
8.1.170.0000.00818.70
8.1.160.0040.00419.30
8.1.150.0040.00419.10
8.1.140.0040.00419.79
8.1.130.0050.00219.14
8.1.120.0030.00517.76
8.1.110.0000.00817.63
8.1.100.0030.00517.78
8.1.90.0040.00417.68
8.1.80.0030.00517.68
8.1.70.0000.00717.78
8.1.60.0040.00417.75
8.1.50.0040.00417.65
8.1.40.0100.00317.71
8.1.30.0040.00417.85
8.1.20.0000.00817.76
8.1.10.0030.00617.80
8.1.00.0000.00817.74
8.0.300.0070.00020.12
8.0.290.0060.00317.13
8.0.280.0000.00718.68
8.0.270.0000.00817.49
8.0.260.0030.00318.68
8.0.250.0000.00717.21
8.0.240.0030.00417.35
8.0.230.0040.00417.32
8.0.220.0000.00717.26
8.0.210.0030.00317.29
8.0.200.0000.00717.33
8.0.190.0050.00517.31
8.0.180.0000.00717.19
8.0.170.0040.00417.21
8.0.160.0000.00717.28
8.0.150.0000.00717.28
8.0.140.0050.00217.14
8.0.130.0050.00013.65
8.0.120.0030.00517.28
8.0.110.0000.00717.13
8.0.100.0020.00517.07
8.0.90.0000.00817.16
8.0.80.0170.00717.24
8.0.70.0030.00517.09
8.0.60.0050.00317.25
8.0.50.0000.00817.16
8.0.30.0070.01117.33
8.0.20.0110.01217.43
8.0.10.0080.00017.40
8.0.00.0060.01217.01
7.4.330.0030.00315.55
7.4.320.0000.00616.79
7.4.300.0000.00616.79
7.4.290.0060.00616.86
7.4.280.0050.00316.80
7.4.270.0030.00317.00
7.4.260.0020.00516.80
7.4.250.0000.00716.62
7.4.240.0020.00517.01
7.4.230.0000.00716.69
7.4.220.0090.00916.75
7.4.210.0090.00616.88
7.4.200.0000.00816.65
7.4.160.0100.00616.78
7.4.150.0170.00417.40
7.4.140.0080.01017.86
7.4.130.0090.00916.79
7.4.120.0110.01016.77
7.4.110.0060.01116.83
7.4.100.0090.00916.73
7.4.90.0100.00716.98
7.4.80.0130.01019.39
7.4.70.0100.00716.94
7.4.60.0060.00916.73
7.4.50.0070.00716.64
7.4.40.0120.00916.66
7.4.30.0000.01716.78
7.4.00.0110.00715.19
7.3.330.0000.00713.54
7.3.320.0030.00313.48
7.3.310.0070.00016.68
7.3.300.0000.00716.45
7.3.290.0070.00916.70
7.3.280.0080.01016.63
7.3.270.0140.01117.40
7.3.260.0100.00716.71
7.3.250.0060.01216.66
7.3.240.0100.00716.76
7.3.230.0120.00416.77
7.3.210.0080.00816.74
7.3.200.0060.00916.46
7.3.190.0030.01316.83
7.3.180.0040.01716.76
7.3.170.0070.00916.54
7.3.160.0100.00716.89
7.2.330.0150.00416.83
7.2.320.0070.01016.86
7.2.310.0100.00716.67
7.2.300.0040.01217.00
7.2.290.0100.00716.73
7.2.60.0120.00016.82
7.2.00.0060.00919.36
7.1.200.0100.00315.79
7.1.100.0040.00818.17
7.1.70.0140.00917.16
7.1.60.0360.01234.82
7.1.50.0360.01334.76
7.1.40.0300.02134.43
7.1.30.0370.01734.29
7.1.20.0400.01334.39
7.1.10.0100.00916.54
7.1.00.0130.01016.59
7.0.200.0130.01116.58
7.0.190.0100.01916.53
7.0.180.0090.01216.29
7.0.170.0110.01016.21
7.0.160.0230.00516.39
7.0.150.0090.01116.22
7.0.140.0130.00816.54
7.0.130.0120.00916.45
7.0.120.0170.02416.53
7.0.110.0130.00716.26
7.0.100.0110.01116.34
7.0.90.0110.01416.21
7.0.80.0100.01316.32
7.0.70.0110.00916.33
7.0.60.0170.00616.06
7.0.50.0140.00816.36
7.0.40.0120.01116.35
7.0.30.0080.01216.51
7.0.20.0090.01316.27
7.0.10.0110.00916.27
7.0.00.0070.01116.25

preferences:
38.23 ms | 400 KiB | 5 Q