3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getFormattedDate(string $date, string $format = 'm/d/Y', string $yearPadding = '19'): string { $sanitizedDate = preg_replace_callback( '~^(\d+)(\D)(\d+)\2(\d{2}|\d{4})$~', fn($m) => sprintf('%02d/%02d/%d', $m[1], $m[3], str_pad($m[4], 4, $yearPadding, STR_PAD_LEFT)), $date ); // sanitize $d = DateTime::createFromFormat($format, $sanitizedDate); // attempt to parse if (!$d) { throw new Exception("Could not parse date: $date"); } $formattedDate = $d->format($format); if ($formattedDate !== $sanitizedDate) { throw new Exception("Date not in a desired American format: $date"); } else { return $date; } } $tests = [ '1-1-1992', '1-1-92', '1-01-1992', '1-01-92', '01-1-1992', '01-1-92', '01-01-1992', '01-01/92', '1/1/1992', '1/1/92', '1/01/1992', '1/01/92', '01/1/199', '01/1/92', '01/01/1992', '01/01/92' ]; foreach ($tests as $test) { try { echo getFormattedDate($test); } catch (Exception $e) { echo $e->getMessage(); } echo "\n"; }

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.4.130.0050.00618.95
8.4.120.0090.01122.39
8.4.110.0080.01318.98
8.4.100.0130.00718.11
8.4.90.0110.01018.40
8.4.80.0090.00921.98
8.4.70.0070.00618.47
8.4.60.0070.00220.24
8.4.50.0160.00618.23
8.4.40.0060.00318.17
8.4.30.0090.00320.39
8.4.20.0040.00420.14
8.4.10.0000.00918.36
8.3.260.0140.00616.73
8.3.250.0130.00617.26
8.3.240.0100.00816.69
8.3.230.0040.00517.12
8.3.220.0130.00717.24
8.3.210.0080.00916.84
8.3.200.0110.01016.82
8.3.190.0100.00916.65
8.3.180.0130.00716.70
8.3.170.0060.00916.97
8.3.160.0030.01716.91
8.3.150.0150.00017.38
8.3.140.0080.00016.93
8.3.130.0040.00418.50
8.3.120.0060.00318.91
8.3.110.0030.00620.94
8.3.100.0110.00018.74
8.3.90.0040.00426.77
8.3.80.0000.01018.56
8.3.70.0150.00717.13
8.3.60.0120.00617.13
8.3.50.0160.00620.36
8.3.40.0120.00320.43
8.3.30.0100.01019.17
8.3.20.0030.00524.18
8.3.10.0080.00824.66
8.3.00.0090.00326.16
8.2.290.0100.01020.61
8.2.280.0080.01217.10
8.2.270.0120.00616.83
8.2.260.0070.00718.96
8.2.250.0080.00017.05
8.2.240.0060.00317.54
8.2.230.0090.00022.58
8.2.220.0060.00337.54
8.2.210.0070.01126.77
8.2.200.0050.00516.75
8.2.190.0110.01118.66
8.2.180.0120.01225.92
8.2.170.0110.01119.33
8.2.160.0000.01422.96
8.2.150.0080.00025.66
8.2.140.0090.00024.66
8.2.130.0040.00426.16
8.2.120.0060.00326.16
8.2.110.0030.00722.32
8.2.100.0000.00918.34
8.2.90.0040.00418.25
8.2.80.0030.00619.41
8.2.70.0090.00018.13
8.2.60.0040.00418.16
8.2.50.0050.00318.25
8.2.40.0040.00418.34
8.2.30.0030.00518.33
8.2.20.0040.00420.45
8.2.10.0040.00418.20
8.2.00.0050.00319.50
8.1.330.0110.00822.16
8.1.320.0080.01116.49
8.1.310.0040.00417.12
8.1.300.0170.00319.82
8.1.290.0070.00430.84
8.1.280.0140.00425.92
8.1.270.0030.00623.99
8.1.260.0070.00726.35
8.1.250.0060.00328.09
8.1.240.0110.00020.85
8.1.230.0060.00618.08
8.1.220.0030.00617.89
8.1.210.0000.01118.77
8.1.200.0000.00917.60
8.1.190.0070.00317.60
8.1.180.0040.00818.10
8.1.170.0090.00318.73
8.1.160.0040.00418.94
8.1.150.0050.00518.87
8.1.140.0000.00717.84
8.1.130.0040.00419.04
8.1.120.0000.00817.76
8.1.110.0050.00217.70
8.1.100.0000.00817.70
8.1.90.0040.00717.76
8.1.80.0000.00817.70
8.1.70.0040.00417.79
8.1.60.0040.00417.87
8.1.50.0000.00817.84
8.1.40.0030.00617.68
8.1.30.0030.00617.84
8.1.20.0180.00017.89
8.1.10.0180.00917.88
8.1.00.0210.00417.91
8.0.300.0040.00418.77
8.0.290.0000.00817.25
8.0.280.0070.00318.50
8.0.270.0000.00818.50
8.0.260.0070.00018.58
8.0.250.0080.00017.30
8.0.240.0040.00417.42
8.0.230.0060.00317.33
8.0.220.0080.00017.21
8.0.210.0000.00717.35
8.0.200.0030.00317.28
8.0.190.0030.00517.44
8.0.180.0000.00817.38
8.0.170.0040.00417.34
8.0.160.0030.01317.24
8.0.150.0110.00017.16
8.0.140.0180.00317.34
8.0.130.0200.00317.22
8.0.120.0130.00817.25
8.0.110.0150.00617.18
8.0.100.0140.00017.35
8.0.90.0060.00917.29
8.0.80.0170.00417.30
8.0.70.0170.00817.20
8.0.60.0170.00617.13
8.0.50.0180.00517.27
8.0.30.0170.00817.17
8.0.20.0250.00417.41
8.0.10.0130.01017.35
7.4.330.0050.00015.55
7.4.320.0000.00716.79
7.4.300.0040.00416.88
7.4.290.0030.00516.77
7.4.280.0030.01116.93
7.4.270.0260.00016.94
7.4.260.0180.01116.89
7.4.250.0180.00816.90
7.4.240.0220.00316.92
7.4.230.0180.00516.86
7.4.220.0100.00816.97
7.4.210.0120.00916.98
7.4.200.0200.00316.80
7.4.190.0040.00617.00
7.4.180.0030.00616.88
7.4.160.0110.00516.99
7.4.150.0190.00316.75
7.4.140.0160.00016.93
7.4.130.0190.00316.78
7.4.120.0210.00016.84
7.4.110.0110.01016.76
7.4.100.0200.00016.81
7.4.90.0180.00016.85
7.4.80.0090.00916.92
7.4.70.0170.00616.82
7.4.60.0170.00416.84
7.4.50.0110.00816.80
7.4.40.0180.00016.77
7.4.30.0110.00716.92
7.4.20.0130.00716.79
7.4.10.0090.00916.66
7.4.00.0180.00316.79

preferences:
28.26 ms | 403 KiB | 5 Q