3v4l.org

run code in 300+ PHP versions simultaneously
<?php function formatPhone($n) { //Remove any parentheses and the numbers they contain: $n = preg_replace("/\([0-9]+?\)/", "", $n); //Strip spaces and non-numeric characters: $n = preg_replace("/[^0-9]/", "", $n); //Strip out leading zeros: $n = ltrim($n, '0'); //Strip out leading +: $n = ltrim($n, '+'); if(strlen($n) <= 10) { if(substr( $n, 0, 2 ) === "39") return preg_replace('/^39/','+3939', $n); else return '+39' + $n; } else if(strlen($n) > 10){ return preg_replace('/^(?:\+?39|0)?/','+39', $n); }else return '+39' + $n; } echo formatPhone("335123456") . "\n"; echo formatPhone("39335123456") . "\n"; echo formatPhone("+39335123456") . "\n"; echo formatPhone("0039335123456") . "\n"; echo formatPhone("039335123456") . "\n"; echo formatPhone("3931234567") . "\n"; echo formatPhone("+39335123456") . "\n"; echo formatPhone("399123456") . "\n"; echo formatPhone("39399123456") . "\n"; echo formatPhone("+39399123456");

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.40.0090.00920.21
8.3.30.0120.00618.54
8.3.20.0090.00024.18
8.3.10.0040.00424.66
8.3.00.0050.00326.16
8.2.170.0140.01119.07
8.2.160.0030.01022.96
8.2.150.0080.00025.66
8.2.140.0040.00424.66
8.2.130.0070.00026.16
8.2.120.0070.00026.35
8.2.110.0070.00420.58
8.2.100.0060.00618.03
8.2.90.0040.00417.63
8.2.80.0000.00817.97
8.2.70.0040.00417.88
8.2.60.0050.00517.50
8.2.50.0050.00318.05
8.2.40.0060.00318.22
8.2.30.0040.00417.96
8.2.20.0050.00218.06
8.2.10.0040.00419.29
8.2.00.0030.00519.19
8.1.270.0000.00823.99
8.1.260.0040.00428.09
8.1.250.0000.00828.09
8.1.240.0060.00323.96
8.1.230.0060.00618.97
8.1.220.0090.00017.75
8.1.210.0030.00618.77
8.1.200.0030.00717.48
8.1.190.0040.00417.50
8.1.180.0030.00518.10
8.1.170.0040.00418.77
8.1.160.0050.00218.98
8.1.150.0040.00418.97
8.1.140.0030.00518.96
8.1.130.0030.00520.04
8.1.120.0070.00017.61
8.1.110.0040.00417.53
8.1.100.0000.00717.59
8.1.90.0040.00417.59
8.1.80.0000.00717.59
8.1.70.0030.00317.59
8.1.60.0030.00517.63
8.1.50.0030.00617.67
8.1.40.0040.00417.57
8.1.30.0000.00717.76
8.1.20.0030.00517.63
8.1.10.0030.00617.64
8.1.00.0030.00617.57
8.0.300.0030.00619.73
8.0.290.0040.00416.88
8.0.280.0040.00418.50
8.0.270.0040.00418.21
8.0.260.0070.00018.34
8.0.250.0070.00017.08
8.0.240.0000.00717.14
8.0.230.0050.00317.07
8.0.220.0030.00317.09
8.0.210.0030.00317.10
8.0.200.0070.00017.20
8.0.190.0070.00017.11
8.0.180.0040.00417.21
8.0.170.0080.00017.12
8.0.160.0030.00517.10
8.0.150.0100.00017.01
8.0.140.0070.00317.07
8.0.130.0050.00013.52
8.0.120.0030.00516.97
8.0.110.0070.00017.12
8.0.100.0080.00016.97
8.0.90.0070.00017.21
8.0.80.0040.01116.96
8.0.70.0090.00016.91
8.0.60.0040.00417.00
8.0.50.0000.00716.87
8.0.30.0070.01017.26
8.0.20.0120.00617.36
8.0.10.0080.00017.18
8.0.00.0120.00616.77
7.4.330.0080.00015.55
7.4.320.0000.00616.79
7.4.300.0000.00616.70
7.4.290.0030.00316.80
7.4.280.0000.00716.71
7.4.270.0030.00316.64
7.4.260.0060.00013.46
7.4.250.0040.00416.78
7.4.240.0030.00616.83
7.4.230.0000.00716.92
7.4.220.0020.00516.75
7.4.210.0120.00716.75
7.4.200.0040.00316.52
7.4.130.0080.01016.71
7.4.120.0060.01216.59
7.4.110.0150.01016.86
7.4.100.0140.00616.81
7.4.90.0150.01116.57
7.4.80.0090.01216.57
7.4.70.0080.01316.46
7.4.60.0170.01016.51
7.4.50.0030.02116.63
7.4.40.0150.01216.54
7.4.30.0000.02716.39
7.4.20.0150.01416.51
7.4.10.0110.01116.46
7.4.00.0140.01116.63
7.3.330.0110.00016.47
7.3.320.0030.00313.46
7.3.310.0030.00316.41
7.3.300.0030.00316.51
7.3.290.0110.00816.54
7.3.260.0110.00816.82
7.3.230.0100.00716.47
7.3.220.0170.00716.53
7.3.210.0160.01316.52
7.3.200.0140.01116.54
7.3.190.0080.01216.74
7.3.180.0150.00916.63
7.3.170.0120.00916.71
7.3.160.0090.01216.51
7.3.150.0230.00516.36
7.3.140.0110.01616.86
7.3.130.0110.01716.57
7.3.120.0130.01016.48
7.3.110.0190.00616.47
7.3.100.0190.00516.80
7.3.90.0200.00416.58
7.3.80.0190.00816.34
7.3.70.0130.01016.50
7.3.60.0190.00816.41
7.3.50.0280.02516.67
7.3.40.0140.00916.53
7.3.30.0180.00616.53
7.3.20.0090.01316.46
7.3.10.0160.00716.47
7.3.00.0200.00616.45
7.2.330.0140.01116.73
7.2.320.0180.00716.65
7.2.310.0160.01116.83
7.2.300.0100.01716.65
7.2.290.0040.02316.66
7.2.280.0170.01216.68
7.2.270.0170.01316.83
7.2.260.0210.00716.64
7.2.250.0190.00516.72
7.2.240.0080.01716.56
7.2.230.0130.01116.72
7.2.220.0140.01016.54
7.2.210.0190.00616.69
7.2.200.0190.01116.55
7.2.190.0150.01316.68
7.2.180.0070.01416.74
7.2.170.0110.01116.60
7.2.160.0180.00916.56
7.2.150.0090.01416.65
7.2.140.0130.01316.81
7.2.130.0200.01016.65
7.2.120.0190.00616.77
7.2.110.0200.00416.60
7.2.100.0150.00716.80
7.2.90.0180.01416.70
7.2.80.0300.01716.60
7.2.70.0140.01116.63
7.2.60.0150.01216.64
7.2.50.0110.01116.89
7.2.40.0170.00916.79
7.2.30.0110.01116.98
7.2.20.0090.01716.90
7.2.10.0190.01116.91
7.2.00.0150.01216.69

preferences:
58.88 ms | 400 KiB | 5 Q