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.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.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.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:
58.58 ms | 400 KiB | 5 Q