3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getFilenameFromUrl($url) { $default = uniqid(); if (!is_string($url) || strpos($url, '/') === false) { return $default; } // Get last part of the url (after the last slash). $parts = explode('/', $url); $filename = array_pop($parts); // Replace special characters with underscores. $filename = preg_replace('/[^a-z0-9\_\-\.]/i', '_', $filename); // Replace multiple underscores with just one. $filename = preg_replace('/__+/i', '_', trim($filename, '_')); // Return the cleaned filename or, if it is empty, a unique id. return $filename ?: $default; } var_dump(getFilenameFromUrl('THIS IS NOT A URL')); var_dump(getFilenameFromUrl('https://example.com/this____or_that______.zip?dlid=asd____a_a_a__b__b__B')); var_dump(getFilenameFromUrl('https://www.some-domain.com/downloads/file.php?file=foobar')); var_dump(getFilenameFromUrl('https://www.some-domain.com/downloads/file.zip?slid=123')); var_dump(getFilenameFromUrl('https://www.some-domain.com/downloads/?file=foobar'));

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)
7.4.10.0100.01015.27
7.4.00.0090.00915.29
7.3.130.0000.02114.92
7.3.120.0070.01115.05
7.3.110.0060.01315.22
7.3.100.0160.00014.63
7.3.90.0060.00615.17
7.3.80.0000.01514.97
7.3.70.0090.00414.83
7.3.60.0120.00415.02
7.3.50.0060.00914.89
7.3.40.0030.01414.69
7.3.30.0060.00615.16
7.3.20.0040.01216.99
7.3.10.0100.00416.65
7.3.00.0050.01016.70
7.2.260.0140.00415.14
7.2.250.0100.00715.29
7.2.240.0080.00815.30
7.2.230.0030.00715.00
7.2.220.0040.01115.24
7.2.210.0000.00915.11
7.2.200.0070.00315.04
7.2.190.0060.00915.15
7.2.180.0070.00715.37
7.2.170.0040.00815.25
7.2.160.0090.00615.22
7.2.150.0060.00317.18
7.2.140.0080.00416.80
7.2.130.0050.00816.99
7.2.120.0510.01016.17
7.2.110.0160.00916.30
7.2.100.0140.00816.13
7.2.90.0170.01016.41
7.2.80.0130.00716.25
7.2.70.0180.00616.48
7.2.60.0130.00816.46
7.2.50.0180.00716.50
7.2.40.0080.01316.56
7.2.30.0430.01116.49
7.2.20.0150.00616.36
7.2.10.0120.01016.33
7.2.00.0100.01116.51
7.1.330.0160.00016.23
7.1.320.0030.01015.86
7.1.310.0030.00616.05
7.1.300.0070.00716.09
7.1.290.0060.00916.08
7.1.280.0090.00316.14
7.1.270.0000.01415.88
7.1.260.0030.01015.64
7.1.250.0070.00415.91
7.1.240.0160.00615.01
7.1.230.0200.00715.12
7.1.220.0200.00815.05
7.1.210.0270.00714.99
7.1.200.0170.01015.17
7.1.190.0140.01014.89
7.1.180.0180.00814.92
7.1.170.0200.00515.06
7.1.160.0150.00914.80
7.1.150.0220.01015.13
7.1.140.0130.00914.87
7.1.130.0210.00614.96
7.1.120.0120.00915.12
7.1.110.0190.00915.12
7.1.100.0130.01115.19
7.1.90.0110.00915.09
7.1.80.0140.00914.97
7.1.70.0160.01015.10
7.1.60.0160.00815.08
7.1.50.0360.00814.99
7.1.40.0120.00714.93
7.1.30.0170.00815.12
7.1.20.0200.00914.92
7.1.10.0200.00714.88
7.1.00.0250.00814.90
7.0.330.0040.01115.30
7.0.320.0000.01115.63
7.0.310.0030.00915.59
7.0.300.0040.01115.75
7.0.290.0040.01115.61
7.0.280.0000.01315.69
7.0.270.0070.00715.52
7.0.260.0130.00015.26
7.0.250.0030.01015.76
7.0.240.0030.01415.80
7.0.230.0060.00615.45
7.0.220.0080.00815.55
7.0.210.0110.00415.57
7.0.200.0080.00615.52
7.0.190.0030.01015.45
7.0.180.0120.00015.54
7.0.170.0070.00715.49
7.0.160.0130.00315.66
7.0.150.0060.00915.32
7.0.140.0030.01015.50
7.0.130.0030.00915.48
7.0.120.0090.00015.69
7.0.110.0090.00315.39
7.0.100.0000.00915.48
7.0.90.0090.00615.73
7.0.80.0030.00615.61
7.0.70.0040.01115.76
7.0.60.0060.00615.56
7.0.50.0030.01215.25
7.0.40.0070.00413.79
7.0.30.0080.00513.81
7.0.20.0050.00513.32
7.0.10.0040.00813.46
7.0.00.0060.00613.88
5.6.400.0030.00814.46
5.6.390.0060.00914.25
5.6.380.0050.00914.00
5.6.370.0030.01014.39
5.6.360.0090.00014.57
5.6.350.0070.00714.58
5.6.340.0080.00614.70
5.6.330.0070.00714.27
5.6.320.0040.00414.50
5.6.310.0060.00314.45
5.6.300.0070.00714.64
5.6.290.0070.00714.22
5.6.280.0070.00714.43
5.6.270.0050.00514.71
5.6.260.0030.01314.09
5.6.250.0060.00914.18
5.6.240.0070.00414.29
5.6.230.0060.00614.23
5.6.220.0030.01014.57
5.6.210.0080.00814.42
5.6.200.0060.00314.32
5.6.190.0060.00614.50
5.6.180.0000.01014.24
5.6.170.0070.00714.46
5.6.160.0070.00714.46
5.6.150.0060.00914.51
5.6.140.0070.00414.41
5.6.130.0040.01114.16
5.6.120.0060.00914.40
5.6.110.0030.00814.47
5.6.100.0080.00614.40
5.6.90.0140.00014.11
5.6.80.0070.00714.17
5.6.70.0060.00614.38
5.6.60.0070.00714.24
5.6.50.0090.00614.06
5.6.40.0060.00914.35
5.6.30.0060.00314.14
5.6.20.0030.00914.34
5.6.10.0030.00914.48
5.6.00.0000.01414.34

preferences:
40.7 ms | 403 KiB | 5 Q