3v4l.org

run code in 300+ PHP versions simultaneously
<?php function trim_slug(string $slug, int $maxlen = 150): string { // check if trimming is required: if(strlen($slug) <= $maxlen) { return $slug; } $pattern = '/^(?<job>.+)(?<loc>-in-\d{5}-.*-.*-\d*)$/'; // $match will have 'job' and 'loc' named keys with the matched values preg_match($pattern, $slug, $match); // raw cut of job name to maximum length: $max_job_chars = $maxlen - strlen($match['loc']); $job_name = substr($match['job'], 0, $max_job_chars); // tidy up to last delimiter, if exists, instead of mincing words: if($last_delim = strrpos($job_name, '-')) { $job_name = substr($match['job'], 0, $last_delim); } return $job_name . $match['loc']; } $string = '/job/hello-this-is-my-job-posting-for-a-daycare-im-looking-for-in-91770-rosemead-california-12345'; echo trim_slug($string, 80);

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.30.0120.00619.54
8.5.20.0080.00920.09
8.5.10.0100.00719.50
8.5.00.0140.00819.82
8.4.180.0090.01320.00
8.4.170.0120.01120.63
8.4.160.0130.01023.94
8.4.150.0020.00014.05
8.4.140.0090.01218.05
8.4.130.0050.00617.58
8.4.120.0070.00224.16
8.4.110.0100.01121.87
8.4.100.0080.01318.54
8.4.90.0120.00918.95
8.4.80.0050.00418.85
8.4.70.0100.01018.17
8.4.60.0140.00918.52
8.4.50.0120.00819.46
8.4.40.0070.01420.74
8.4.30.0110.00722.05
8.4.20.0200.00018.29
8.4.10.0030.00622.14
8.3.300.0120.01220.97
8.3.290.0080.01220.85
8.3.280.0080.01218.66
8.3.270.0100.01016.81
8.3.260.0070.00316.92
8.3.250.0070.00119.01
8.3.240.0070.00617.21
8.3.230.0100.01016.95
8.3.220.0050.00319.27
8.3.210.0080.01016.74
8.3.200.0070.00216.92
8.3.190.0120.00717.28
8.3.180.0130.00516.75
8.3.170.0070.01118.94
8.3.160.0120.00416.79
8.3.150.0150.00419.21
8.3.140.0000.00817.59
8.3.130.0080.00016.95
8.3.120.0110.00720.75
8.3.110.0070.00320.94
8.3.100.0030.00616.75
8.3.90.0040.00426.77
8.3.80.0090.00018.43
8.3.70.0090.00916.63
8.3.60.0040.01516.62
8.3.50.0070.01018.47
8.3.40.0120.00320.23
8.3.30.0130.00318.88
8.3.20.0000.00824.18
8.3.10.0080.00024.66
8.3.00.0040.00426.16
8.2.300.0140.00822.20
8.2.290.0120.00720.20
8.2.280.0120.00818.65
8.2.270.0070.01119.15
8.2.260.0110.00416.96
8.2.250.0110.00417.09
8.2.240.0060.00317.46
8.2.230.0060.00322.58
8.2.220.0090.00024.06
8.2.210.0070.00426.77
8.2.200.0040.00716.50
8.2.190.0090.01316.88
8.2.180.0120.00625.92
8.2.170.0090.00619.04
8.2.160.0030.01022.96
8.2.150.0070.00025.66
8.2.140.0030.00524.66
8.2.130.0070.00026.16
8.2.120.0000.01117.93
8.2.110.0070.00422.38
8.2.100.0090.00318.03
8.2.90.0040.00417.97
8.2.80.0060.00317.97
8.2.70.0000.00817.88
8.2.60.0150.00317.50
8.2.50.0160.00317.50
8.2.40.0170.00017.50
8.2.30.0080.00817.63
8.2.20.0130.00317.38
8.2.10.0120.00417.50
8.2.00.0100.00717.48
8.1.340.0140.00721.95
8.1.330.0080.01121.98
8.1.320.0120.01016.40
8.1.310.0040.00418.65
8.1.300.0040.00418.22
8.1.290.0090.00030.84
8.1.280.0160.00025.92
8.1.270.0000.00924.66
8.1.260.0080.00026.35
8.1.250.0070.00028.09
8.1.240.0060.00322.37
8.1.230.0040.00720.97
8.1.220.0050.00317.74
8.1.210.0000.00819.06
8.1.200.0030.00517.60
8.1.190.0050.01117.47
8.1.180.0120.00417.00
8.1.170.0150.00017.13
8.1.160.0130.00317.13
8.1.150.0140.00317.00
8.1.140.0130.00317.13
8.1.130.0140.00317.25
8.1.120.0060.01017.25
8.1.110.0160.00017.34
8.1.100.0070.01017.13
8.1.90.0190.00017.25
8.1.80.0060.01017.24
8.1.70.0120.00417.38
8.1.60.0190.00017.60
8.1.50.0140.00317.38
8.1.40.0150.00817.25
8.1.30.0100.01017.50
8.1.20.0150.00317.50
8.1.10.0100.00717.25
8.1.00.0110.00717.09
8.0.300.0050.00220.14
8.0.290.0000.00717.00
8.0.280.0120.00416.59
8.0.270.0160.00016.52
8.0.260.0100.00716.75
8.0.250.0100.00716.63
8.0.240.0090.00616.88
8.0.230.0160.00316.63
8.0.220.0110.00616.72
8.0.210.0080.00816.52
8.0.200.0120.00516.52
8.0.190.0140.00316.60
8.0.180.0090.00916.52
8.0.170.0150.00316.75
8.0.160.0080.00816.52
8.0.150.0110.00616.59
8.0.140.0170.00016.63
8.0.130.0160.00016.52
8.0.120.0150.00316.61
8.0.110.0080.00816.52
8.0.100.0110.00516.75
8.0.90.0120.00416.63
8.0.80.0170.00016.52
8.0.70.0080.00816.63
8.0.60.0110.00616.63
8.0.50.0070.01016.60
8.0.30.0180.00016.63
8.0.20.0120.00716.75
8.0.10.0160.00316.52

preferences:
31.51 ms | 475 KiB | 5 Q