3v4l.org

run code in 500+ PHP versions simultaneously
<?php $filedata = <<<EOT <?xml version="1.0" encoding="utf-8" ?> <article xmlns="http://docbook.org/ns/docbook" version="5.0" xmlns:xlink="http://www.w3.org/1999/xlink" > <para> This is an <emphasis role="strong">hello <em>world</em></emphasis> sentence. </para> </article> EOT; $dom = new DOMDocument(); $dom->loadXML($filedata); foreach($dom->documentElement->childNodes as $node){ if(XML_ELEMENT_NODE === $node->nodeType && 'para' === $node->nodeName){ // Replace any emphasis elements foreach($node->childNodes as $childNode) { if(XML_ELEMENT_NODE === $childNode->nodeType && 'emphasis' === $childNode->nodeName){ // This is arguably the most "correct" way to replace, just in case // there's extra nodes inside. A cheaper way would be to not loop // and just use the nodeValue however you might lose some HTML. $newNode = $dom->createElement('b'); foreach($childNode->childNodes as $grandChild){ $newNode->appendChild($grandChild->cloneNode(true)); } $childNode->replaceWith($newNode); } } // Build our output $output = ''; foreach($node->childNodes as $childNode) { $output .= $dom->saveHTML($childNode); } // The provided XML has a namespace, and when cloning nodes that NS comes // along. Since we are going from regular XML to irregular HTML I think // a string replacement is best. $output = str_replace(' xmlns="http://docbook.org/ns/docbook"', '', $output); echo $output; } }

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.60.0050.00317.34
8.5.50.0090.00916.91
8.5.30.0090.00917.69
8.5.20.0110.00719.63
8.5.10.0080.01022.08
8.5.00.0100.01120.36
8.4.210.0100.00919.98
8.4.180.0160.00720.07
8.4.170.0110.01120.00
8.4.160.0110.01124.13
8.4.150.0080.00517.06
8.4.140.0100.01318.02
8.4.130.0110.01017.89
8.4.120.0090.01118.13
8.4.110.0070.00618.22
8.4.100.0070.01317.77
8.4.90.0120.00920.79
8.4.80.0060.00319.07
8.4.70.0090.00718.42
8.4.60.0160.00419.21
8.4.50.0050.00318.01
8.4.40.0110.00719.78
8.4.30.0100.01019.02
8.4.20.0130.00717.98
8.4.10.0060.00322.25
8.3.300.0100.01120.75
8.3.290.0090.01021.19
8.3.280.0140.00618.74
8.3.270.0120.00816.91
8.3.260.0110.00617.02
8.3.250.0140.00617.45
8.3.240.0090.00917.14
8.3.230.0130.00617.01
8.3.220.0120.00619.31
8.3.210.0100.00918.61
8.3.200.0050.00418.89
8.3.190.0080.00819.31
8.3.180.0130.00617.19
8.3.170.0110.00717.41
8.3.160.0040.00716.96
8.3.150.0120.00317.51
8.3.140.0040.00417.49
8.3.130.0000.00918.77
8.3.120.0070.00320.96
8.3.110.0090.00620.46
8.3.100.0090.00017.22
8.3.90.0000.00826.77
8.3.80.0070.00317.00
8.3.70.0150.00618.40
8.3.60.0220.00018.68
8.3.50.0110.00420.32
8.3.40.0070.00720.59
8.3.30.0070.00719.14
8.3.20.0040.00424.18
8.3.10.0040.00424.66
8.3.00.0040.00426.16
8.2.300.0110.00922.44
8.2.290.0090.00616.98
8.2.280.0120.00818.77
8.2.270.0110.00716.84
8.2.260.0150.00017.54
8.2.250.0040.00416.83
8.2.240.0040.01219.30
8.2.230.0130.00720.94
8.2.220.0030.00624.06
8.2.210.0060.00326.77
8.2.200.0030.00616.88
8.2.190.0140.00717.00
8.2.180.0040.01125.92
8.2.170.0040.01119.51
8.2.160.0070.00722.96
8.2.150.0040.00425.66
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0050.00326.16
8.2.110.0080.00320.79
8.2.100.0030.01018.28
8.2.90.0040.00419.57
8.2.80.0030.00517.97
8.2.70.0030.00617.88
8.2.60.0060.00318.18
8.2.50.0030.00518.07
8.2.40.0040.00418.53
8.2.30.0030.00618.56
8.2.20.0040.00419.70
8.2.10.0070.00018.55
8.2.00.0080.00019.59
8.1.340.0150.00917.73
8.1.330.0120.00716.19
8.1.320.0110.00916.65
8.1.310.0070.00717.15
8.1.300.0060.00316.50
8.1.290.0090.00030.84
8.1.280.0110.00425.92
8.1.270.0070.00024.66
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0030.00624.21
8.1.230.0040.00719.60
8.1.220.0000.00818.13
8.1.210.0040.00418.77
8.1.200.0100.00017.61
8.1.190.0050.00317.73
8.1.180.0050.00318.10
8.1.170.0000.00819.04
8.1.160.0000.00719.25
8.1.150.0000.00819.02
8.1.140.0040.00417.82
8.1.130.0070.00019.39
8.1.120.0040.00417.73
8.1.110.0000.00817.68
8.1.100.0070.00117.73
8.1.90.0050.01017.66
8.1.80.0130.00017.81
8.1.70.0110.00517.82
8.1.60.0190.00017.79
8.1.50.0060.01117.75
8.1.40.0080.00817.82
8.1.30.0110.00017.91
8.1.20.0120.00617.94
8.1.10.0120.00717.85
8.1.00.0170.00317.78
8.0.300.0050.00318.77
8.0.290.0100.00017.25
8.0.280.0030.00318.79
8.0.270.0040.00417.11
8.0.260.0070.00018.75
8.0.250.0050.00217.43
8.0.240.0000.00717.38
8.0.230.0110.00217.29
8.0.220.0100.00717.31
8.0.210.0090.00617.34
8.0.200.0150.00017.38
8.0.190.0150.00017.17
8.0.180.0140.00017.31
8.0.170.0110.00317.27
8.0.160.0130.00317.21
8.0.150.0070.00717.13
8.0.140.0080.00817.20
8.0.130.0090.00417.09
8.0.120.0130.00217.28
8.0.110.0100.00517.20
8.0.100.0070.00717.21
8.0.90.0090.00617.30
8.0.80.0140.00317.27
8.0.70.0140.00317.23
8.0.60.0140.00317.19
8.0.50.0120.00417.25
8.0.30.0130.00317.28
8.0.20.0070.00917.32
8.0.10.0160.00017.34
7.4.330.0000.00515.55
7.4.320.0000.00616.68
7.4.300.0120.00516.84
7.4.290.0130.00416.84
7.4.280.0140.00316.74
7.4.270.0140.00416.90
7.4.260.0180.00016.77
7.4.250.0110.00616.72
7.4.240.0040.01216.80
7.4.230.0150.00316.73
7.4.220.0090.00616.86
7.4.210.0110.00316.66
7.4.200.0120.00316.72
7.4.190.0160.00016.70
7.4.180.0080.00316.62
7.4.160.0070.00716.77
7.4.150.0120.00316.77
7.4.140.0090.00616.79
7.4.130.0080.00816.74
7.4.120.0150.00016.78
7.4.110.0070.00716.78
7.4.100.0120.00416.75
7.4.90.0090.00016.80
7.4.80.0050.00316.62
7.4.70.0100.00016.63
7.4.60.0030.00716.55
7.4.50.0040.00416.67
7.4.40.0080.00016.50
7.4.30.0000.01116.66
7.4.20.0140.00216.64
7.4.10.0070.00716.70
7.4.00.0150.00016.74

preferences:
96.88 ms | 1257 KiB | 5 Q