3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ "123_String" => "String", "233718_This_is_a_string" => "This_is_a_string", "83_Another Example" => "Another Example", ]; function viaExplode($string) { return explode('_', $string, 2)[1]; // the limit parameter gives reliability } function viaLtrim($string) { return ltrim($string, '0..9_'); // because character after first underscore is not a digit or underscore } function viaPregMatch($string) { return preg_match('/\d+_\K.+/', $string, $m) ? $m[0] : null; } function viaPregReplace($string) { return preg_replace('/^\d+_/', '', $string); } function viaSscanf($string) { return sscanf($string, '%*d_%[^\d]')[0]; // because no numbers in trailing substring } foreach ($tests as $test => $desired) { printf( "%s: %s, %s, %s, %s, %s\n", str_pad($test, 25, ' '), viaLtrim($test), viaPregMatch($test), viaPregReplace($test), viaExplode($test), viaSscanf($test) ); }

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.5.10.0090.01216.89
8.5.00.0140.00820.30
8.4.150.0010.00114.05
8.4.140.0100.01117.52
8.4.130.0070.00319.66
8.4.120.0140.00620.57
8.4.110.0150.00622.64
8.4.100.0150.00818.05
8.4.90.0050.00718.68
8.4.80.0140.00817.93
8.4.70.0130.00717.74
8.4.60.0080.01019.15
8.4.50.0080.00818.03
8.4.40.0030.01617.78
8.4.30.0030.01620.71
8.4.20.0130.00619.66
8.4.10.0060.00319.63
8.3.280.0130.00718.23
8.3.270.0120.00716.72
8.3.260.0130.00616.64
8.3.250.0100.00818.94
8.3.240.0120.00616.74
8.3.230.0140.00516.82
8.3.220.0040.00317.22
8.3.210.0020.00516.60
8.3.200.0030.00616.73
8.3.190.0060.00317.26
8.3.180.0100.00816.62
8.3.170.0030.01517.12
8.3.160.0060.01218.80
8.3.150.0040.01518.55
8.3.140.0040.00417.22
8.3.130.0050.00317.10
8.3.120.0070.00318.95
8.3.110.0000.00920.94
8.3.100.0070.00324.06
8.3.90.0080.00826.77
8.3.80.0070.00317.97
8.3.70.0090.00616.74
8.3.60.0080.00818.65
8.3.50.0090.00616.78
8.3.40.0150.00020.50
8.3.30.0140.00719.16
8.3.20.0040.00424.18
8.3.10.0040.00424.66
8.3.00.0050.00326.16
8.2.290.0110.00720.54
8.2.280.0040.00420.49
8.2.270.0030.01417.25
8.2.260.0040.00416.75
8.2.250.0060.00317.08
8.2.240.0040.01517.41
8.2.230.0080.00022.58
8.2.220.0030.00637.54
8.2.210.0050.00226.77
8.2.200.0090.00016.63
8.2.190.0140.00316.88
8.2.180.0100.01016.75
8.2.170.0100.01019.13
8.2.160.0070.00722.96
8.2.150.0030.00525.66
8.2.140.0070.00024.66
8.2.130.0080.00026.16
8.2.120.0040.00421.02
8.2.110.0170.00021.16
8.2.100.0190.00718.44
8.2.90.0200.00718.44
8.2.80.0170.00918.44
8.2.70.0220.00718.44
8.2.60.0200.00818.44
8.2.50.0250.00218.44
8.2.40.0250.00218.44
8.2.30.0170.00818.44
8.2.20.0190.00718.44
8.2.10.0240.00418.44
8.2.00.0150.01018.44
8.1.330.0120.00722.03
8.1.320.0110.01116.50
8.1.310.0000.00818.66
8.1.300.0060.00318.38
8.1.290.0030.00630.84
8.1.280.0180.00025.92
8.1.270.0070.00024.66
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0060.00319.34
8.1.230.0250.00518.44
8.1.220.0220.00718.44
8.1.210.0240.00318.44
8.1.200.0150.00918.44
8.1.190.0230.00018.44
8.1.180.0210.00318.44
8.1.170.0220.00318.44
8.1.160.0220.00618.44
8.1.150.0240.00318.44
8.1.140.0180.00618.44
8.1.130.0210.00318.44
8.1.120.0170.00818.44
8.1.110.0160.00818.44
8.1.100.0180.00618.44
8.1.90.0200.00518.44
8.1.80.0240.00018.44
8.1.70.0210.00418.44
8.1.60.0200.00618.44
8.1.50.0190.00818.44
8.1.40.0230.00218.44
8.1.30.0240.00218.44
8.1.20.0220.00418.44
8.1.10.0200.00618.44
8.1.00.0150.00718.44
8.0.300.0190.00618.44
8.0.290.0200.00418.44
8.0.280.0250.00318.44
8.0.270.0190.00618.44
8.0.260.0190.00518.44
8.0.250.0220.00318.44
8.0.240.0260.00018.44
8.0.230.0200.00518.44
8.0.220.0240.00118.44
8.0.210.0140.01018.44
8.0.200.0200.00418.44
8.0.190.0200.00718.44
8.0.180.0220.00318.44
8.0.170.0170.00818.44
8.0.160.0240.00118.44
8.0.150.0180.01118.44
8.0.140.0200.00618.44
8.0.130.0230.00618.44
8.0.120.0200.00718.44
8.0.110.0180.00618.44
8.0.100.0160.00818.44
8.0.90.0240.00118.44
8.0.80.0180.00718.44
8.0.70.0210.00418.44
8.0.60.0210.00518.44
8.0.50.0190.00418.44
8.0.30.0240.00218.44
8.0.20.0200.00618.44
8.0.10.0160.01018.44

preferences:
96.88 ms | 403 KiB | 5 Q