3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = "Jim & Bob's (amazing!) Photo #2 w/Susan [@Melbourne, Australia].jpg"; echo nl2br($str ."\n"); echo sanitizeFilename($str); function sanitizeFilename($f) { //FROM: http://www.house6.com/blog/?p=83 // a combination of various methods // we don't want to convert html entities, or do any url encoding // we want to retain the "essence" of the original file name, if possible // char replace table found at: // http://www.php.net/manual/en/function.strtr.php#98669 /* Usage example: $str = "Jim & Bob's (amazing!) Photo #2 [@Melbourne, Australia].jpg"; echo sanitizeFilename($str); // Outputs: // jim-and-bobs-amazing-photo-number-2-at-melbourne-australia.jpg */ $replace_chars = array( 'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f' ); $f = strtr($f, $replace_chars); // convert & to "and", @ to "at", and # to "number" $f = preg_replace(array('/[\&]/', '/[\@]/', '/[\#]/' ), array('-and-', '-at-', '-number-'), $f); $f = preg_replace('/[^(\x20-\x7F)]*/','', $f); // removes any special chars we missed $f = str_replace(' ', '-', $f); // convert space to hyphen $f = str_replace('\'', '', $f); // removes apostrophes $f = preg_replace('/[^\w\-\.]+/', '', $f); // remove non-word chars (leaving hyphens and periods) $f = preg_replace('/[\-]+/', '-', $f); // converts groups of hyphens into one $abbrev_words = [ ['word' => 'S', 'abbrev' => 'South'], ['word' => 'W', 'abbrev' => 'West'], ['word' => 'N', 'abbrev' => 'North'], ['word' => 'E', 'abbrev' => 'East'], ]; foreach ($abbrev_words as $row) { $search[] = '/(?<=\s|^)' . preg_quote($row['word'], '/') . '\b/i'; $abbrev[] = $row['abbrev']; } $title = "Heaven's Basement in W Virginia"; echo preg_replace($search, $abbrev, $title); return strtolower($f); }

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.130.0060.00318.67
8.3.120.0170.00319.07
8.3.110.0000.00820.94
8.3.100.0060.00324.06
8.3.90.0050.00326.77
8.3.80.0030.00617.97
8.3.70.0110.01516.86
8.3.60.0060.00916.88
8.3.50.0060.01323.03
8.3.40.0090.00619.10
8.3.30.0110.00319.39
8.3.20.0000.00820.32
8.3.10.0040.00423.66
8.3.00.0050.00319.69
8.2.250.0060.00316.93
8.2.240.0000.00917.39
8.2.230.0090.00022.58
8.2.220.0040.00437.54
8.2.210.0050.00326.77
8.2.200.0070.00316.63
8.2.190.0070.01118.26
8.2.180.0130.00616.88
8.2.170.0100.01022.96
8.2.160.0100.00320.35
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0070.00026.16
8.2.120.0000.00920.64
8.2.110.0070.00322.42
8.2.100.0110.00017.97
8.2.90.0060.00319.20
8.2.80.0000.00818.03
8.2.70.0050.00317.88
8.2.60.0040.00418.04
8.2.50.0080.00318.07
8.2.40.0060.00319.91
8.2.30.0040.00419.82
8.2.20.0040.00417.97
8.2.10.0000.00818.13
8.2.00.0060.00317.89
8.1.300.0160.00018.07
8.1.290.0030.00630.84
8.1.280.0100.00725.92
8.1.270.0060.00322.22
8.1.260.0070.00026.35
8.1.250.0080.00028.09
8.1.240.0060.00323.82
8.1.230.0040.00818.89
8.1.220.0000.00817.74
8.1.210.0030.00518.77
8.1.200.0060.00317.50
8.1.190.0080.00017.36
8.1.180.0090.00318.10
8.1.170.0060.00318.78
8.1.160.0070.00022.08
8.1.150.0040.00418.82
8.1.140.0060.00617.62
8.1.130.0000.00717.79
8.1.120.0000.00717.56
8.1.110.0040.00417.54
8.1.100.0050.00317.52
8.1.90.0030.00517.69
8.1.80.0040.00317.65
8.1.70.0070.00017.54
8.1.60.0000.00817.80
8.1.50.0030.00617.61
8.1.40.0040.00417.70
8.1.30.0050.00317.70
8.1.20.0000.00817.79
8.1.10.0060.00317.66
8.1.00.0030.00517.58
8.0.300.0000.00820.71
8.0.290.0000.00717.18
8.0.280.0030.00318.54
8.0.270.0000.00717.36
8.0.260.0050.00317.32
8.0.250.0000.00717.14
8.0.240.0020.00517.20
8.0.230.0000.00717.22
8.0.220.0000.00717.20
8.0.210.0070.00017.05
8.0.200.0030.00317.13
8.0.190.0000.00717.28
8.0.180.0030.00617.05
8.0.170.0040.00417.07
8.0.160.0000.00717.21
8.0.150.0090.00017.15
8.0.140.0000.00716.98
8.0.130.0000.00613.60
8.0.120.0040.00417.10
8.0.110.0040.00417.00
8.0.100.0050.00217.20
8.0.90.0080.00017.25
8.0.80.0100.00717.20
8.0.70.0000.00717.19
8.0.60.0040.00417.20
8.0.50.0040.00416.95
8.0.30.0080.01117.44
8.0.20.0090.01117.58
8.0.10.0050.00317.24
8.0.00.0090.00916.88
7.4.330.0020.00215.03
7.4.320.0000.00616.69
7.4.300.0000.00716.85
7.4.290.0000.00716.76
7.4.280.0040.00416.64
7.4.270.0000.00716.83
7.4.260.0000.00716.86
7.4.250.0040.00416.64
7.4.240.0030.00516.68
7.4.230.0030.00316.55
7.4.220.0120.01216.72
7.4.210.0070.01416.95
7.4.200.0000.00816.75
7.4.160.0100.00716.70
7.4.150.0100.01017.40
7.4.140.0090.00917.86
7.4.130.0080.00916.75
7.4.120.0040.01616.72
7.4.110.0140.00716.79
7.4.100.0000.01716.95
7.4.90.0070.01016.63
7.4.80.0070.01019.39
7.4.70.0110.00716.75
7.4.60.0050.01216.65
7.4.50.0000.00916.59
7.4.40.0070.01416.74
7.4.30.0070.01416.89
7.4.00.0110.00715.09
7.3.330.0000.00713.48
7.3.320.0030.00313.48
7.3.310.0070.00016.43
7.3.300.0070.00016.53
7.3.290.0060.00816.57
7.3.280.0130.00316.55
7.3.270.0130.00417.40
7.3.260.0030.01316.59
7.3.250.0120.00816.59
7.3.240.0110.00716.87
7.3.230.0060.01216.82
7.3.210.0070.01016.54
7.3.200.0090.01319.39
7.3.190.0120.00616.54
7.3.180.0030.01316.54
7.3.170.0090.00916.55
7.3.160.0100.00716.93
7.3.120.0070.01314.85
7.3.110.0070.01014.99
7.3.100.0030.01115.33
7.3.90.0060.00914.98
7.3.80.0100.00315.30
7.3.70.0060.00915.16
7.3.60.0030.01015.13
7.3.50.0110.00414.71
7.3.40.0040.01114.88
7.3.30.0060.00915.12
7.3.20.0110.00317.04
7.3.10.0070.00816.67
7.3.00.0070.00816.69
7.2.330.0150.00316.89
7.2.320.0070.01016.93
7.2.310.0130.00716.81
7.2.300.0070.01016.88
7.2.290.0090.00916.84
7.2.250.0080.01115.22
7.2.240.0040.01615.26
7.2.230.0030.00615.28
7.2.220.0000.01415.23
7.2.210.0130.00315.11
7.2.200.0040.01115.08
7.2.190.0030.01015.15
7.2.180.0030.01415.32
7.2.170.0060.01215.23
7.2.130.0110.00817.14
7.2.120.0080.01016.97
7.2.110.0170.00717.03
7.2.100.0130.00917.03
7.2.90.0200.00716.83
7.2.80.0140.00916.95
7.2.70.0240.00317.16
7.2.60.0100.01117.09
7.2.50.0150.00916.95
7.2.40.0110.01217.13
7.2.30.0090.00616.88
7.2.20.0090.00916.98
7.2.10.0040.01216.94
7.2.00.0030.01217.91
7.1.330.0070.01016.30
7.1.320.0070.00415.96
7.1.310.0060.00916.16
7.1.300.0090.00016.15
7.1.290.0090.00615.80
7.1.280.0090.00615.84
7.1.270.0000.01515.96
7.1.260.0030.00916.05
7.1.250.0050.00915.79
7.1.200.0060.00615.95
7.1.100.0240.00418.42
7.1.70.0050.00517.29
7.1.60.0130.01319.57
7.1.50.0060.01217.20
7.1.00.0030.07722.46
7.0.200.0040.00416.82
7.0.140.0030.07321.97
7.0.60.0070.05319.97
7.0.50.0030.05317.89
7.0.40.0000.05720.18
7.0.30.0300.06320.33
7.0.20.0300.05020.44
7.0.10.0030.04320.08
7.0.00.0030.08720.12
5.6.280.0000.08021.11
5.6.210.0030.07720.79
5.6.200.0130.06718.32
5.6.190.0030.04720.33
5.6.180.0200.07320.61
5.6.170.0200.05720.50
5.6.160.0070.08720.59
5.6.150.0100.06318.26
5.6.140.0000.04318.19
5.6.130.0030.04718.22
5.6.120.0100.07021.02
5.6.110.0070.09021.03
5.6.100.0030.09020.98
5.6.90.0070.04721.14
5.6.80.0030.07020.39
5.5.350.0070.08020.42
5.5.340.0100.03318.01
5.5.330.0130.08320.47
5.5.320.2200.03720.33
5.5.310.0270.07720.34
5.5.300.0070.05317.97
5.5.290.0130.08017.99
5.5.280.0070.08020.93
5.5.270.0100.08721.00
5.5.260.0200.06720.83
5.5.250.0000.04320.83
5.5.240.0200.04020.23
5.4.450.1200.04319.53
5.4.440.0330.05019.58
5.4.430.0230.05319.39
5.4.420.0130.05019.21
5.4.410.0070.05718.73
5.4.400.0100.05318.90
5.4.390.0370.05718.56
5.4.380.0170.05018.80
5.4.370.0070.06018.52
5.4.360.0170.04018.75
5.4.350.0070.04318.70
5.4.340.0070.04718.47
5.4.320.0170.04718.63
5.4.310.0170.03718.53
5.4.300.0200.03718.56
5.4.290.0130.05318.64
5.4.280.0070.05318.68
5.4.270.0070.06018.74
5.4.260.0170.04018.76
5.4.250.0200.03718.55
5.4.240.0130.04318.46
5.4.230.0200.04018.59
5.4.220.0170.04318.64
5.4.210.0170.03718.55
5.4.200.0100.04016.66
5.4.190.0130.04718.70
5.4.180.0070.05718.54
5.4.170.0200.04318.50
5.4.160.0230.04018.66
5.4.150.0170.04718.72
5.4.140.0130.03716.37
5.4.130.0070.04716.27
5.4.120.0030.04716.22
5.4.110.0070.04316.32
5.4.100.0030.05316.27
5.4.90.0070.04716.45
5.4.80.0170.04016.15
5.4.70.0170.04716.24
5.4.60.0100.05016.29
5.4.50.0170.04316.33
5.4.40.0100.05016.21
5.4.30.0070.04716.29
5.4.20.0100.05016.43
5.4.10.0200.04316.41
5.4.00.0130.05015.78
5.3.290.0070.05714.73
5.3.280.0100.04714.57
5.3.270.0070.05014.77
5.3.260.0030.06314.69
5.3.250.0230.04314.59
5.3.240.0170.04014.56
5.3.230.0170.03714.61
5.3.220.0070.03714.57
5.3.210.0100.04014.69
5.3.200.0070.04014.51
5.3.190.0170.03714.58
5.3.180.0100.03714.74
5.3.170.0030.04314.61
5.3.160.0100.04314.72
5.3.150.0170.04014.63
5.3.140.0170.05014.64
5.3.130.0200.04714.70
5.3.120.0130.05714.56
5.3.110.0030.04714.63
5.3.100.0100.06014.01
5.3.90.0170.06013.95
5.3.80.0230.04014.16
5.3.70.0030.04013.97
5.3.60.0000.04014.01
5.3.50.0030.03714.00
5.3.40.0070.04314.04
5.3.30.0270.03314.07
5.3.20.0100.06013.74
5.3.10.0270.04313.64
5.3.00.0330.03313.71
5.2.170.0070.04311.21
5.2.160.0100.04011.14
5.2.150.0130.03711.32
5.2.140.0170.04311.14
5.2.130.0030.04711.15
5.2.120.0030.04711.10
5.2.110.0030.04011.11
5.2.100.0000.04011.16
5.2.90.0030.04311.11
5.2.80.0030.04311.19
5.2.70.0100.03711.11
5.2.60.0130.03011.06
5.2.50.0000.04311.21
5.2.40.0070.03711.09
5.2.30.0030.04310.97
5.2.20.0100.03311.05
5.2.10.0030.03711.06
5.2.00.0070.04010.80
5.1.60.0070.03310.20
5.1.50.0070.03310.05
5.1.40.0030.03310.05
5.1.30.0070.03310.39
5.1.20.0070.03010.42
5.1.10.0070.03310.18
5.1.00.0030.04010.07
5.0.50.0030.0308.65
5.0.40.0100.0238.57
5.0.30.0070.0408.26
5.0.20.0030.0278.18
5.0.10.0100.0278.16
5.0.00.0070.0378.33
4.4.90.0100.0175.98
4.4.80.0030.0205.92
4.4.70.0000.0175.90
4.4.60.0000.0235.84
4.4.50.0000.0205.94
4.4.40.0030.0275.86
4.4.30.0030.0175.85
4.4.20.0070.0136.02
4.4.10.0070.0175.92
4.4.00.0030.0275.90
4.3.110.0030.0135.84
4.3.100.0000.0175.78
4.3.90.0070.0135.93
4.3.80.0000.0305.89
4.3.70.0030.0205.79
4.3.60.0030.0205.88
4.3.50.0000.0235.78
4.3.40.0000.0335.71
4.3.30.0030.0204.60
4.3.20.0070.0204.62
4.3.10.0030.0204.46
4.3.00.0230.01314.98

preferences:
29.16 ms | 403 KiB | 5 Q