3v4l.org

run code in 300+ PHP versions simultaneously
<?php //+ Jonas Raoni Soares Silva //@ http://jsfromhell.com class String{ public static function truncate($s, $l, $e = '...', $isHTML = false){ $i = 0; $tags = array(); if($isHTML){ preg_match_all('/<[^>]+>([^<]*)/', $s, $m, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); foreach($m as $o){ if($o[0][1] - $i >= $l) break; $t = substr(strtok($o[0][0], " \t\n\r\0\x0B>"), 1); if($t[0] != '/') $tags[] = $t; elseif(end($tags) == substr($t, 1)) array_pop($tags); $i += $o[1][1] - $o[0][1]; } } return substr($s, 0, $l = min(strlen($s), $l + $i)) . (count($tags = array_reverse($tags)) ? '</' . implode('></', $tags) . '>' : '') . (strlen($s) > $l ? $e : ''); } } echo String::truncate('jo<i><b>n</b>as</i>', 3, '&hellip;'); //jo<... echo "<hr>"; echo String::truncate('jo<i><b>n</b>as</i>', 3, '&hellip;', true); //jo<i><b>n</b></i>... echo "<hr>"; echo String::truncate('jo<i><b>n</b>as</i>', 3, '&hellip;', true, false); //jo<i><b>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)
5.6.280.0170.06320.88
5.6.250.0070.03720.74
5.6.240.0000.04320.61
5.6.230.0030.04320.55
5.6.220.0000.03720.57
5.6.210.0030.04020.44
5.6.200.0030.04021.01
5.6.190.0030.05021.00
5.6.180.0070.03720.93
5.6.170.0030.04321.13
5.6.160.0100.06720.99
5.6.150.0130.08021.09
5.6.140.0100.07721.02
5.6.130.0100.08021.04
5.6.120.0070.08021.14
5.6.110.0030.08321.09
5.6.100.0170.06721.00
5.6.90.0000.05021.11
5.6.80.0100.07020.36
5.6.70.0100.08020.37
5.6.60.0070.07720.30
5.6.50.0070.08320.43
5.6.40.0130.07320.34
5.6.30.0100.07720.28
5.6.20.0070.05320.37
5.6.10.0070.04720.34
5.6.00.0070.07720.31
5.5.380.0130.03320.32
5.5.370.0100.03320.36
5.5.360.0000.05020.27
5.5.350.0070.03720.34
5.5.340.0030.05020.84
5.5.330.0030.06720.73
5.5.320.0030.04720.75
5.5.310.0030.04320.82
5.5.300.0130.08020.61
5.5.290.0230.07020.80
5.5.280.0000.09020.74
5.5.270.0030.08320.85
5.5.260.0070.08020.85
5.5.250.0130.07320.54
5.5.240.0130.07320.27
5.5.230.0100.08320.18
5.5.220.0070.08020.14
5.5.210.0000.08720.22
5.5.200.0100.08020.18
5.5.190.0070.07020.23
5.5.180.0130.07020.15
5.5.160.0070.08320.11
5.5.150.0100.06320.10
5.5.140.0130.07020.20
5.5.130.0000.06720.14
5.5.120.0070.08020.11
5.5.110.0000.06020.12
5.5.100.0000.08320.12
5.5.90.0070.08020.08
5.5.80.0030.07319.97
5.5.70.0070.07320.10
5.5.60.0070.08320.11
5.5.50.0000.08319.89
5.5.40.0070.07319.98
5.5.30.0000.08320.02
5.5.20.0070.07320.05
5.5.10.0230.06019.98
5.5.00.0030.08019.98
5.4.450.0000.09019.42
5.4.440.0000.08719.36
5.4.430.0130.06719.55
5.4.420.0100.07719.49
5.4.410.0070.06019.34
5.4.400.0000.08319.16
5.4.390.0030.08019.15
5.4.380.0070.07019.02
5.4.370.0100.06319.05
5.4.360.0130.04019.03
5.4.350.0200.06718.95
5.4.340.0230.06319.07
5.4.320.0070.08319.20
5.4.310.0070.05019.23
5.4.300.0170.04719.13
5.4.290.0070.07719.21
5.4.280.0070.07319.04
5.4.270.0100.07719.23
5.4.260.0030.08318.95
5.4.250.0100.07719.23
5.4.240.0000.08019.04
5.4.230.0130.07019.02
5.4.220.0100.07019.04
5.4.210.0170.06719.13
5.4.200.0070.06018.88
5.4.190.0170.06719.02
5.4.180.0030.08019.15
5.4.170.0170.06319.20
5.4.160.0100.07019.08
5.4.150.0070.07718.94
5.4.140.0030.07016.36
5.4.130.0100.06316.42
5.4.120.0070.07716.20
5.4.110.0100.07316.49
5.4.100.0070.07716.49
5.4.90.0070.07716.52
5.4.80.0070.05016.35
5.4.70.0130.06016.35
5.4.60.0130.06316.42
5.4.50.0100.06716.32
5.4.40.0130.05316.54
5.4.30.0100.07316.35
5.4.20.0130.06716.39
5.4.10.0100.07016.45
5.4.00.0100.07015.78
5.3.290.0030.08014.80
5.3.280.0070.07714.57
5.3.270.0070.07714.64
5.3.260.0100.06714.64
5.3.250.0000.07714.76
5.3.240.0070.05314.58
5.3.230.0100.06714.64
5.3.220.0030.06714.72
5.3.210.0070.07314.65
5.3.200.0070.08014.66
5.3.190.0070.07314.65
5.3.180.0130.07014.51
5.3.170.0000.07314.69
5.3.160.0100.07314.51
5.3.150.0130.06314.69
5.3.140.0030.07714.63
5.3.130.0070.05714.55
5.3.120.0070.07314.63
5.3.110.0100.07714.54
5.3.100.0100.07314.15
5.3.90.0170.06014.17
5.3.80.0070.06314.10
5.3.70.0200.06314.10
5.3.60.0000.05014.04
5.3.50.0030.07714.02
5.3.40.0100.08013.86
5.3.30.0070.06313.91
5.3.20.0070.07013.80
5.3.10.0070.06313.76
5.3.00.0070.07013.71
5.2.170.0030.06311.08
5.2.160.0100.06011.26
5.2.150.0100.06011.30
5.2.140.0000.07311.08
5.2.130.0070.06011.15
5.2.120.0030.07011.20
5.2.110.0030.06311.13
5.2.100.0070.05711.11
5.2.90.0070.05711.18
5.2.80.0030.04711.14
5.2.70.0030.05711.17
5.2.60.0100.05310.98
5.2.50.0030.06310.95
5.2.40.0070.06010.94
5.2.30.0030.06311.12
5.2.20.0030.06310.99
5.2.10.0000.03710.79
5.2.00.0000.06310.74
5.1.60.0030.05310.08
5.1.50.0070.0409.85
5.1.40.0070.04310.11
5.1.30.0070.05310.41
5.1.20.0000.04710.23
5.1.10.0070.05010.18
5.1.00.0070.04710.10
5.0.50.0170.0339.18
5.0.40.0030.0439.18
5.0.30.0130.0539.18
5.0.20.0070.0409.18
5.0.10.0030.0439.18
5.0.00.0000.0579.18
4.4.90.0000.0379.18
4.4.80.0030.0339.18
4.4.70.0000.0339.18
4.4.60.0030.0339.18
4.4.50.0000.0339.18
4.4.40.0030.0539.18
4.4.30.0030.0239.18
4.4.20.0000.0379.18
4.4.10.0030.0279.18
4.4.00.0000.0309.18
4.3.110.0030.0339.18
4.3.100.0070.0309.18
4.3.90.0000.0339.18
4.3.80.0030.0539.18
4.3.70.0030.0279.18
4.3.60.0000.0339.18
4.3.50.0030.0339.18
4.3.40.0000.0539.18
4.3.30.0030.0279.18
4.3.20.0000.0339.18
4.3.10.0030.0339.18
4.3.00.0000.0379.18

preferences:
143.78 ms | 1386 KiB | 7 Q