3v4l.org

run code in 300+ PHP versions simultaneously
<?php $original_string = '<p>some text&nbsp;<img src="data:image/png;base64,randomIMGData" data-filename="file1.png" style="width: 120px;"><img src="data:image/jpeg;base64,moreIMGData" data-filename="file2.jpg" style="width: 120px;"><p>Some other text<p><img alt="Regular image" src="http://example.com/"><img src="data:image/png;base64,invalidElement" style="width: 120px;"></p>'; $doc = new DOMDocument(); // Treat the string as a frament and do not add a DOCTYPE or mandatory tags $doc->loadHTML($original_string, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); // Get all images $imgs = $doc->getElementsByTagName('img'); $id_noveho_clanku = 'testdir'; foreach ($imgs as $img) { $src = $img->getAttribute('src'); $name = $img->getAttribute('data-filename'); // Check if it contains base64 data and a filename if (false !== strpos($src, 'data:image') && "" !== $img->getAttribute('data-filename')) { $data = substr($src, strpos($src, ',') + 1); // Data start $img->setAttribute('src', str_replace($data, '', $src)); // Remove data $name = substr($name, 0, strrpos($name, '.')); // Save the image to disk $path = "../img/clanky/${id_noveho_clanku}/${name}.txt"; // file_put_contents ($path, $data); echo "Saving image data: '${data}' to ${path}\n"; } } // Get the HTML with the data removed $parsed = $doc->saveHTML($doc); echo $parsed;

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.0080.00116.96
8.5.00.0150.00820.40
8.4.150.0030.00014.05
8.4.140.0130.00917.82
8.4.130.0140.00718.35
8.4.120.0150.00422.35
8.4.110.0130.00719.19
8.4.100.0100.01118.18
8.4.90.0120.01118.17
8.4.80.0150.00718.00
8.4.70.0070.00517.87
8.4.60.0120.00918.81
8.4.50.0060.00422.66
8.4.40.0100.01019.60
8.4.30.0030.00718.77
8.4.20.0030.01719.25
8.4.10.0030.00618.15
8.3.280.0120.00818.80
8.3.270.0090.01017.18
8.3.260.0040.00517.07
8.3.250.0060.00219.35
8.3.240.0170.00317.15
8.3.230.0100.00517.15
8.3.220.0100.01017.64
8.3.210.0110.00717.07
8.3.200.0040.00416.81
8.3.190.0090.00917.59
8.3.180.0090.00721.07
8.3.170.0090.00916.87
8.3.160.0130.00716.63
8.3.150.0100.01017.34
8.3.140.0060.01216.95
8.3.130.0030.00518.73
8.3.120.0130.00618.99
8.3.110.0000.00920.94
8.3.100.0110.00024.06
8.3.90.0040.00416.90
8.3.80.0000.00918.80
8.3.70.0060.00917.00
8.3.60.0070.00717.00
8.3.50.0050.01322.11
8.3.40.0090.00918.85
8.3.30.0060.01019.09
8.3.20.0080.00022.53
8.3.10.0040.00422.29
8.3.00.0040.00423.76
8.2.290.0030.00620.73
8.2.280.0100.01018.80
8.2.270.0100.01017.37
8.2.260.0140.00419.27
8.2.250.0110.00417.02
8.2.240.0030.00517.57
8.2.230.0060.00322.58
8.2.220.0040.00437.54
8.2.210.0080.00026.77
8.2.200.0090.00016.88
8.2.190.0080.00816.88
8.2.180.0090.00916.88
8.2.170.0110.00422.96
8.2.160.0110.00720.60
8.2.150.0030.00524.18
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0050.00320.92
8.2.110.0030.00619.54
8.2.100.0120.00517.97
8.2.90.0000.00819.63
8.2.80.0060.00319.61
8.2.70.0000.00817.75
8.2.60.0040.00418.05
8.2.50.0080.00018.07
8.2.40.0030.00520.07
8.2.30.0000.00718.29
8.2.20.0070.00018.18
8.2.10.0040.00419.45
8.2.00.0060.00319.64
8.1.330.0050.00318.43
8.1.320.0190.00516.12
8.1.310.0140.00316.85
8.1.300.0080.00018.16
8.1.290.0030.00618.88
8.1.280.0150.00325.92
8.1.270.0080.00020.98
8.1.260.0080.00026.35
8.1.250.0050.00328.09
8.1.240.0030.00619.37
8.1.230.0070.00421.35
8.1.220.0000.00918.26
8.1.210.0100.00019.26
8.1.200.0060.00317.72
8.1.190.0000.00817.35
8.1.180.0080.00018.10
8.1.170.0030.00519.11
8.1.160.0050.00319.12
8.1.150.0040.00419.08
8.1.140.0000.00721.27
8.1.130.0000.00720.41
8.1.120.0040.00417.67
8.1.110.0000.01117.60
8.1.100.0030.00517.79
8.1.90.0050.00217.64
8.1.80.0040.00417.71
8.1.70.0000.00817.66
8.1.60.0040.00417.87
8.1.50.0000.00817.80
8.1.40.0110.00017.81
8.1.30.0040.00417.79
8.1.20.0040.00417.94
8.1.10.0050.00317.74
8.1.00.0040.00417.71
8.0.300.0040.00420.29
8.0.290.0070.00017.13
8.0.280.0070.00018.64
8.0.270.0000.00717.43
8.0.260.0000.00620.25
8.0.250.0070.00017.19
8.0.240.0060.00017.17
8.0.230.0000.00717.13
8.0.220.0040.00417.08
8.0.210.0040.00417.11
8.0.200.0050.00317.18
8.0.190.0030.00517.20
8.0.180.0030.00617.20
8.0.170.0040.00517.18
8.0.160.0040.00417.07
8.0.150.0070.00017.02
8.0.140.0050.00217.11
8.0.130.0000.00513.55
8.0.120.0000.00817.05
8.0.110.0070.00017.11
8.0.100.0080.00016.98
8.0.90.0080.00016.93
8.0.80.0060.01017.06
8.0.70.0000.00817.22
8.0.60.0000.00817.13
8.0.50.0030.00517.13
8.0.30.0070.01017.49
8.0.20.0090.00917.21
8.0.10.0040.00417.24
8.0.00.0140.00717.05
7.4.330.0020.00215.55
7.4.320.0030.00316.80
7.4.300.0000.00816.82
7.4.290.0000.00716.72
7.4.280.0080.00016.66
7.4.270.0050.00316.74
7.4.260.0030.00313.52
7.4.250.0030.00616.76
7.4.240.0020.00516.79
7.4.230.0000.00816.80
7.4.220.0030.00316.90
7.4.210.0070.00916.85
7.4.200.0000.00716.78
7.4.140.0100.00617.86
7.4.130.0090.00916.79
7.4.120.0040.01416.59
7.4.110.0030.01416.68
7.4.100.0120.00616.66
7.4.90.0070.01116.98
7.4.80.0060.01619.39
7.4.70.0060.01716.60
7.4.60.0100.00716.79
7.4.50.0030.01216.54
7.4.40.0070.01416.83
7.4.00.0090.01015.13
7.3.330.0020.00516.55
7.3.320.0030.00313.40
7.3.310.0040.00416.46
7.3.300.0030.00316.48
7.3.290.0030.00316.41
7.3.280.0030.01216.61
7.3.260.0110.00916.71
7.3.240.0100.00816.68
7.3.230.0030.01516.36
7.3.210.0090.00916.61
7.3.200.0060.01216.90
7.3.190.0050.01116.84
7.3.180.0130.00316.85
7.3.170.0090.01216.52
7.3.160.0070.01316.63
7.3.120.0110.00915.10
7.3.110.0090.00914.94
7.3.100.0070.01014.86
7.3.90.0030.01014.62
7.3.80.0120.00514.83
7.3.70.0090.00614.67
7.3.60.0090.00514.88
7.3.50.0120.00815.02
7.3.40.0080.01314.83
7.3.30.0110.00614.81
7.3.20.0150.00815.76
7.3.10.0120.00515.67
7.3.00.0140.00615.90
7.2.330.0120.00616.71
7.2.320.0070.01017.11
7.2.310.0070.01116.76
7.2.300.0030.01516.58
7.2.290.0080.00816.92
7.2.250.0040.01515.11
7.2.240.0070.01415.20
7.2.230.0040.01115.13
7.2.220.0130.00015.33
7.2.210.0080.00815.33
7.2.200.0120.00315.15
7.2.190.0050.01115.11
7.2.180.0070.00715.16
7.2.170.0050.01215.05
7.2.160.0040.01114.85
7.2.150.0250.00315.12
7.2.140.0130.01015.13
7.2.130.0220.00414.84
7.2.120.0190.00615.30
7.2.110.0150.01214.94
7.2.100.0180.00414.86
7.2.90.0260.00015.19
7.2.80.0230.00715.32
7.2.70.0270.00715.34
7.2.60.0220.00315.02
7.2.50.0280.00015.09
7.2.40.0200.01115.05
7.2.30.0220.00315.20
7.2.20.0200.00315.11
7.2.10.0170.00615.13
7.2.00.0130.01315.13
7.1.330.0040.00815.80
7.1.320.0030.01015.82
7.1.310.0140.00815.02
7.1.300.0100.00914.95
7.1.290.0150.00615.02
7.1.280.0130.00314.81
7.1.270.0370.00715.03
7.1.260.0100.00914.85
7.1.250.0420.00314.20

preferences:
163.73 ms | 403 KiB | 5 Q