3v4l.org

run code in 300+ PHP versions simultaneously
<?php // eliminar esta etiqueta usando expresiones regulares php // https://es.stackoverflow.com/q/131277/127 $html = ' <p><figure><img src="xxxx"></figure></p> <p> <figure> <img src="2222"> </figure> </p>'; //Generar el DOM $dom = new DOMDocument; $libxml_opciones = LIBXML_COMPACT | LIBXML_HTML_NODEFDTD | LIBXML_NONET | LIBXML_NOERROR; @$dom->loadHTML($html, $libxml_opciones); //Generar un XPath para búsquedas $xpath = new DOMXpath($dom); //Obtener todos los tags <p> $p_nodelist = $dom->getElementsByTagName('p'); //Bucle para cada <p> (en orden inverso para preservar la estructura) for ($i = $p_nodelist->length; --$i >= 0; ) { $p = $p_nodelist->item($i); $p_hijos = $xpath->query('./*',$p); //Si el <p> tiene un único hijo, y ese hijo es un <figure> if ($p_hijos->length == 1 && $p_hijos->item(0)->tagName == 'figure') { $figure = $p_hijos->item(0); //Si el <figure> tiene un único hijo, y ese hijo es una <img> $figure_hijos = $xpath->query('./*',$figure); if ($figure_hijos->length == 1 && $figure_hijos->item(0)->tagName == 'img') { //REEMPLAZAR todo el <p> por solamente el <figure> $p->parentNode->replaceChild($figure,$p); } } } //Guardar el html $resultado = ''; foreach ($dom->documentElement->lastChild->childNodes as $elem) { $resultado .= $dom->saveHTML($elem); } //Imprimir el resultado echo $resultado;

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.0130.00318.90
8.3.50.0040.01816.98
8.3.40.0080.00819.34
8.3.30.0140.00019.17
8.3.20.0040.00420.54
8.3.10.0040.00424.04
8.3.00.0090.00019.63
8.2.180.0120.00318.57
8.2.170.0040.01222.96
8.2.160.0110.00420.79
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0060.00319.63
8.2.120.0080.00026.35
8.2.110.0060.00321.50
8.2.100.0090.00318.16
8.2.90.0000.00820.75
8.2.80.0040.00418.00
8.2.70.0060.00318.13
8.2.60.0060.00318.00
8.2.50.0040.00418.13
8.2.40.0040.00420.94
8.2.30.0050.00319.82
8.2.20.0030.00618.57
8.2.10.0030.00518.46
8.2.00.0040.00418.76
8.1.280.0150.00325.92
8.1.270.0000.00820.46
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0030.00619.63
8.1.230.0120.00021.26
8.1.220.0040.00418.04
8.1.210.0050.00619.29
8.1.200.0040.00417.61
8.1.190.0030.00717.73
8.1.180.0030.00518.10
8.1.170.0000.00818.70
8.1.160.0000.00719.38
8.1.150.0070.00419.36
8.1.140.0000.00819.39
8.1.130.0000.00817.86
8.1.120.0040.00417.91
8.1.110.0000.00717.76
8.1.100.0090.00017.89
8.1.90.0040.00417.87
8.1.80.0080.00317.91
8.1.70.0000.00717.76
8.1.60.0040.00417.88
8.1.50.0040.00417.82
8.1.40.0040.00417.92
8.1.30.0030.00517.97
8.1.20.0000.00818.10
8.1.10.0040.00417.99
8.1.00.0040.00417.85
8.0.300.0040.00420.39
8.0.290.0000.00717.00
8.0.280.0000.00718.89
8.0.270.0000.00717.56
8.0.260.0030.00517.24
8.0.250.0000.00717.39
8.0.240.0000.00717.36
8.0.230.0060.00317.39
8.0.220.0030.00417.18
8.0.210.0040.00417.21
8.0.200.0030.00317.34
8.0.190.0000.00817.39
8.0.180.0000.00717.25
8.0.170.0050.00317.31
8.0.160.0060.00317.32
8.0.150.0040.00717.27
8.0.140.0080.00017.18
8.0.130.0030.00313.82
8.0.120.0050.00517.33
8.0.110.0070.00017.35
8.0.100.0040.00417.13
8.0.90.0000.00817.38
8.0.80.0060.01017.30
8.0.70.0080.00017.41
8.0.60.0000.00817.25
8.0.50.0000.00817.37
8.0.30.0090.01017.44
8.0.20.0120.00717.53
8.0.10.0030.00617.40
8.0.00.0110.00917.13
7.4.330.0050.00015.55
7.4.320.0030.00317.01
7.4.300.0060.00016.96
7.4.290.0030.00317.04
7.4.280.0080.00016.81
7.4.270.0000.00817.03
7.4.260.0050.00316.93
7.4.250.0040.00416.84
7.4.240.0000.00717.04
7.4.230.0000.00817.12
7.4.220.0040.00416.79
7.4.210.0100.00317.05
7.4.200.0000.00717.12
7.4.160.0090.00616.95
7.4.150.0120.00617.40
7.4.140.0120.00917.86
7.4.130.0180.00617.00
7.4.120.0120.01116.96
7.4.110.0130.00816.70
7.4.100.0120.00617.09
7.4.90.0060.01016.85
7.4.80.0080.01519.39
7.4.70.0060.01116.93
7.4.60.0110.00617.05
7.4.50.0030.01116.80
7.4.40.0090.00917.02
7.4.10.0110.00715.03
7.4.00.0120.00515.19
7.3.330.0030.00313.59
7.3.320.0000.00613.54
7.3.310.0000.00816.67
7.3.300.0030.00316.52
7.3.290.0050.00916.67
7.3.280.0030.01316.56
7.3.270.0100.00717.40
7.3.260.0130.00616.90
7.3.250.0130.00516.72
7.3.240.0070.01316.81
7.3.230.0070.01016.70
7.3.210.0090.00716.72
7.3.200.0090.00616.88
7.3.190.0040.01316.55
7.3.180.0100.00616.96
7.3.170.0090.01517.02
7.3.160.0130.00316.90
7.3.130.0070.01115.19
7.3.120.0100.01015.26
7.3.110.0060.01214.98
7.3.100.0090.00615.04
7.3.90.0030.01714.80
7.3.80.0070.01115.24
7.3.70.0000.01414.96
7.3.60.0110.00414.98
7.3.50.0030.01014.89
7.3.40.0030.00915.00
7.3.30.0100.00014.76
7.3.20.0080.01216.92
7.3.10.0060.01316.56
7.3.00.0040.01116.70
7.2.330.0120.00817.18
7.2.320.0110.01217.12
7.2.310.0060.01216.97
7.2.300.0100.01316.94
7.2.290.0040.01317.17
7.2.260.0060.01315.29
7.2.250.0100.00715.08
7.2.240.0100.00315.32
7.2.230.0130.00615.19
7.2.220.0080.00815.36
7.2.210.0070.01315.20
7.2.200.0120.00015.33
7.2.190.0070.00715.32
7.2.180.0000.01015.51
7.2.170.0060.00915.09
7.2.160.0100.00715.33
7.2.150.0060.00917.14
7.2.140.0040.01117.06
7.2.130.0030.00717.23
7.2.120.0160.00317.09
7.2.110.0000.01217.25
7.2.100.0000.01417.30
7.2.90.0030.01317.15
7.2.80.0000.01617.38
7.2.70.0040.01216.86
7.2.60.0080.00617.16
7.2.50.0090.00617.05
7.2.40.0040.01216.89
7.2.30.0100.00617.13
7.2.20.0000.01717.07
7.2.10.0180.01117.61
7.2.00.0230.00517.34
7.1.330.0000.01316.18
7.1.320.0000.01515.86
7.1.310.0030.00915.89
7.1.300.0120.00315.80
7.1.290.0000.01315.95
7.1.280.0090.00916.01
7.1.270.0110.00315.95
7.1.260.0040.01115.99
7.1.250.0030.00615.98
7.1.240.0100.00615.91
7.1.230.0070.01015.90
7.1.220.0030.00916.02
7.1.210.0030.01016.08
7.1.200.0110.00616.04
7.1.190.0090.00916.15
7.1.180.0070.00715.90
7.1.170.0000.01315.75
7.1.160.0030.00915.96
7.1.150.0000.01115.86
7.1.140.0090.00015.74
7.1.130.0190.00816.42
7.1.120.0150.01116.39
7.1.110.0170.00716.27
7.1.100.0140.01016.18
7.1.90.0250.00516.21
7.1.80.0180.01016.32
7.1.70.0210.00315.79
7.1.60.0260.00624.76
7.1.50.0290.01024.52
7.1.40.0250.01224.32
7.1.30.0320.00724.36
7.1.20.0320.00224.39
7.1.10.0170.01015.47
7.1.00.0210.00715.60
7.0.330.0040.01515.52
7.0.320.0030.00715.52
7.0.310.0070.00715.62
7.0.300.0030.01015.50
7.0.290.0040.01115.47
7.0.280.0100.00315.56
7.0.270.0070.00415.56
7.0.260.0000.01315.71
7.0.250.0100.00315.63
7.0.240.0070.00715.85
7.0.230.0070.00715.46
7.0.220.0030.01415.68
7.0.210.0000.00815.68
7.0.200.0040.01115.68
7.0.190.0000.01415.46
7.0.180.0060.01015.34
7.0.170.0090.00315.54
7.0.160.0040.01115.53
7.0.150.0030.01215.41
7.0.140.0090.00315.52
7.0.130.0070.00715.81
7.0.120.0040.00715.39
7.0.110.0080.00315.54
7.0.100.0000.01015.38
7.0.90.0040.00715.69
7.0.80.0040.01115.63
7.0.70.0070.00715.25
7.0.60.0090.00015.61
7.0.50.0030.00715.84
7.0.40.0040.00813.71
7.0.30.0060.00613.69
7.0.20.0080.00313.68
7.0.10.0030.00513.61
7.0.00.0060.00613.63
5.6.400.0070.00714.82
5.6.390.0030.01314.51
5.6.380.0060.00914.89
5.6.370.0060.01314.50
5.6.360.0030.01314.75
5.6.350.0060.00614.87
5.6.340.0030.00914.51
5.6.330.0070.00714.80
5.6.320.0070.00714.75
5.6.310.0000.00914.54
5.6.300.0030.00714.32
5.6.290.0030.01014.74
5.6.280.0000.01214.52
5.6.270.0030.00914.53
5.6.260.0070.00714.65
5.6.250.0040.01114.82
5.6.240.0080.00314.47
5.6.230.0000.00914.66
5.6.220.0000.01114.46
5.6.210.0030.01014.39
5.6.200.0030.01014.80
5.6.190.0070.00314.61
5.6.180.0110.00414.79
5.6.170.0060.00614.92
5.6.160.0000.01314.66
5.6.150.0000.01414.48
5.6.140.0030.00614.54
5.6.130.0070.00414.52
5.6.120.0040.01114.52
5.6.110.0050.00514.98
5.6.100.0060.00614.80
5.6.90.0090.00314.40
5.6.80.0070.00414.44
5.6.70.0030.00614.77
5.6.60.0030.01014.41
5.6.50.0140.00014.39
5.6.40.0000.01314.40
5.6.30.0110.00314.63
5.6.20.0000.01214.63
5.6.10.0060.00614.60
5.6.00.0040.00714.36

preferences:
68.87 ms | 401 KiB | 5 Q