3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = "<p>This paragraph has <b>bold text</b> &amp; <a href='#'>links with <b>bold text</b></a>.</p>"; // load into dom $doc = new DOMDocument(); $doc->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); function replaceOneTag($tag) { static $counter = 0; $counter++; return "<a href='#{$counter}'>{$tag}</a>"; } function replaceTags(array $tags, $node) { // skip links if ($node instanceof DOMElement && $node->hasAttribute("href")) { // skip } // process elements else if ($node instanceof DOMText) { // render back to html, which will deal with entities $oldhtml = $node->ownerDocument->saveHTML($node); // replace tags $newhtml = preg_replace_callback('#\b(' . implode('|', $tags) . ')\b#', function($match) { return replaceOneTag($match[0]); }, $oldhtml); // load the new html string into the document and replace the current DOMText node $newnode = $node->ownerDocument->createDocumentFragment(); $newnode->appendXML($newhtml); $node->parentNode->replaceChild($newnode, $node); } // handle other children else if ($node instanceof DOMNode && $node->hasChildNodes()) { // the child node list updates as the document is modified, which affects the foreach for ($child = $node->firstChild; $child; $child = $nextchild) { // get the next child node in advance $nextchild = $child->nextSibling; replaceTags($tags, $child); } } } print_r(replaceTags(["paragraph", "bold"], $doc)); echo $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.5.10.0130.00617.14
8.5.00.0110.01120.54
8.4.150.0020.00014.05
8.4.140.0130.00918.05
8.4.130.0070.00518.75
8.4.120.0050.00524.68
8.4.110.0060.00620.86
8.4.100.0100.01119.02
8.4.90.0110.01020.79
8.4.80.0050.00819.02
8.4.70.0100.00919.29
8.4.60.0050.01019.25
8.4.50.0090.00618.38
8.4.40.0100.01020.91
8.4.30.0060.00318.80
8.4.20.0100.01019.11
8.4.10.0060.00320.14
8.3.280.0100.01019.00
8.3.270.0090.01116.96
8.3.260.0090.01117.16
8.3.250.0110.00819.25
8.3.240.0100.01017.73
8.3.230.0130.00717.02
8.3.220.0060.00319.26
8.3.210.0100.00918.98
8.3.200.0040.00516.93
8.3.190.0110.01017.56
8.3.180.0100.01117.20
8.3.170.0160.00317.45
8.3.160.0100.01016.99
8.3.150.0190.00017.45
8.3.140.0090.00019.13
8.3.130.0030.01718.84
8.3.120.0090.00619.36
8.3.110.0030.01218.73
8.3.100.0100.01017.12
8.3.90.0130.00726.77
8.3.80.0000.00917.25
8.3.70.0090.00917.00
8.3.60.0100.01017.13
8.3.50.0100.01016.64
8.3.40.0180.00319.25
8.3.30.0000.01519.21
8.3.20.0080.00024.18
8.3.10.0000.00924.66
8.3.00.0040.00426.16
8.2.290.0060.00220.69
8.2.280.0120.00822.62
8.2.270.0160.00317.04
8.2.260.0070.01116.98
8.2.250.0130.00317.02
8.2.240.0100.00019.24
8.2.230.0060.00320.94
8.2.220.0040.00424.06
8.2.210.0040.00426.77
8.2.200.0090.00016.88
8.2.190.0090.01216.88
8.2.180.0150.00025.92
8.2.170.0120.00419.59
8.2.160.0070.00722.96
8.2.150.0000.00925.66
8.2.140.0030.00524.66
8.2.130.0040.00426.16
8.2.120.0050.00319.86
8.2.110.0000.00822.65
8.2.100.0090.00320.07
8.2.90.0000.00818.13
8.2.80.0040.00419.45
8.2.70.0060.00318.18
8.2.60.0050.00318.44
8.2.50.0040.00418.13
8.2.40.0030.00621.48
8.2.30.0000.00919.55
8.2.20.0050.00318.58
8.2.10.0050.00219.53
8.2.00.0040.00419.59
8.1.330.0150.00422.31
8.1.320.0110.01018.75
8.1.310.0080.00016.60
8.1.300.0030.00618.62
8.1.290.0000.00930.84
8.1.280.0110.01125.92
8.1.270.0000.00824.21
8.1.260.0030.00626.35
8.1.250.0040.00428.09
8.1.240.0090.00922.48
8.1.230.0110.00018.33
8.1.220.0050.00318.04
8.1.210.0000.00818.77
8.1.200.0060.00317.85
8.1.190.0060.00317.63
8.1.180.0060.00318.10
8.1.170.0000.00819.16
8.1.160.0030.00620.90
8.1.150.0000.00719.24
8.1.140.0040.00419.27
8.1.130.0000.00720.60
8.1.120.0000.00817.82
8.1.110.0080.00017.82
8.1.100.0000.00817.92
8.1.90.0000.00817.81
8.1.80.0080.00017.80
8.1.70.0030.00317.93
8.1.60.0000.00918.05
8.1.50.0030.00517.98
8.1.40.0000.00817.99
8.1.30.0050.00318.09
8.1.20.0040.00418.03
8.1.10.0040.00417.91
8.1.00.0000.00817.97
8.0.300.0040.00418.77
8.0.290.0070.00017.13
8.0.280.0030.00318.82
8.0.270.0000.00717.31
8.0.260.0060.00018.89
8.0.250.0050.00317.34
8.0.240.0080.00017.28
8.0.230.0040.00417.31
8.0.220.0000.00717.39
8.0.210.0020.00517.23
8.0.200.0030.00517.41
8.0.190.0000.00717.43
8.0.180.0060.00717.40
8.0.170.0000.00817.30
8.0.160.0040.00417.19
8.0.150.0120.00017.17
8.0.140.0030.00517.33
8.0.130.0000.00713.70
8.0.120.0050.00317.31
8.0.110.0090.00017.37
8.0.100.0080.00017.11
8.0.90.0000.00717.36
8.0.80.0060.00917.37
8.0.70.0000.01717.28
8.0.60.0040.01617.19
8.0.50.0000.01617.32
8.0.30.0120.00917.33
8.0.20.0110.00717.42
8.0.10.0090.01217.53
8.0.00.0070.01017.38
7.4.330.0030.00315.55
7.4.320.0030.00316.95
7.4.300.0000.00617.04
7.4.290.0030.00517.00
7.4.280.0040.00417.02
7.4.270.0030.00316.94
7.4.260.0050.00013.66
7.4.250.0050.00217.01
7.4.240.0000.00817.13
7.4.230.0000.00716.90
7.4.220.0000.00716.91
7.4.210.0100.01016.94
7.4.200.0100.00317.04
7.4.190.0040.01117.26
7.4.180.0100.00717.05
7.4.160.0140.00316.97
7.4.150.0040.01517.20
7.4.140.0110.01517.03
7.4.130.0140.01416.94
7.4.120.0060.01516.96
7.4.110.0160.00717.03
7.4.100.0080.01316.98
7.4.90.0190.00616.98
7.4.80.0150.00317.11
7.4.70.0100.01017.12
7.4.60.0110.00417.05
7.4.50.0030.01917.05
7.4.40.0180.00416.85
7.4.30.0040.01517.13
7.4.20.0080.01617.07
7.4.10.0120.00616.89
7.4.00.0170.00017.00
7.3.330.0000.00816.58
7.3.320.0080.00013.71
7.3.310.0000.00716.77
7.3.300.0030.00316.79
7.3.290.0070.01016.67
7.3.280.0220.00616.69
7.3.270.0230.00716.59
7.3.260.0320.01816.70
7.3.250.0180.00916.71
7.3.240.0190.01316.74
7.3.230.0060.01716.76
7.3.220.0120.01216.71
7.3.210.0100.01016.77
7.3.200.0090.00616.74
7.3.190.0100.00916.76
7.3.180.0060.01016.73
7.3.170.0000.01816.65
7.3.160.0060.01216.71
7.3.150.0060.00916.68
7.3.140.0000.01316.70
7.3.130.0120.00316.65
7.3.120.0160.00616.62
7.3.110.0090.00616.58
7.3.100.0040.01216.59
7.3.90.0000.01416.95
7.3.80.0030.01716.72
7.3.70.0120.00916.86
7.3.60.0130.00616.89
7.3.50.0110.00816.89
7.3.40.0100.01016.91
7.3.30.0130.00616.90
7.3.20.0070.01416.91
7.3.10.0100.01016.89
7.3.00.0070.00716.77

preferences:
40.75 ms | 403 KiB | 5 Q