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, ' ...'); //jo<... echo "\n\n\n"; echo String::truncate('jo<i><b>n</b>as</i>', 3, ' ...', true); //jo<i><b>n</b></i>... echo "\n\n\n"; echo String::truncate('jo<i><b>n</b>as</i>', 3, ' ...', 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.0070.07021.09
5.6.210.0100.07720.76
5.6.200.0070.07718.30
5.6.190.0070.07320.48
5.6.180.0270.08020.61
5.6.170.0300.06720.63
5.6.160.0100.06720.71
5.6.150.0130.07718.26
5.6.140.0070.07718.12
5.6.130.0130.06718.18
5.6.120.0030.05721.11
5.6.110.0070.08321.02
5.6.100.0030.05720.98
5.6.90.0100.07021.00
5.6.80.0100.07320.42
5.6.70.0300.06720.41
5.5.350.0070.07720.43
5.5.340.0100.08317.95
5.5.330.0100.06320.18
5.5.320.0400.07320.27
5.5.310.0200.06320.26
5.5.300.0000.09017.93
5.5.290.0070.04018.04
5.5.280.0100.07020.85
5.5.270.0170.07320.91
5.5.260.0100.08020.81
5.5.250.0000.08320.70
5.5.240.0100.06320.18
5.4.450.0470.05043.94
5.4.440.0370.04743.92
5.4.430.0370.04743.90
5.4.420.0200.04743.90
5.4.410.0400.04343.89
5.4.400.0200.03343.86
5.4.390.0130.03743.80
5.4.380.0100.05718.76
5.4.370.0100.05718.74
5.4.360.0130.05018.61
5.4.350.0230.04718.52
5.4.340.0170.05018.73
5.4.320.0090.03412.52
5.4.310.0090.04112.52
5.4.300.0030.03912.52
5.4.290.0060.03612.51
5.4.280.0070.04012.41
5.4.270.0040.03812.41
5.4.260.0080.04012.41
5.4.250.0090.03412.40
5.4.240.0030.03912.41
5.4.230.0040.03912.40
5.4.220.0060.03512.40
5.4.210.0060.03812.39
5.4.200.0050.04112.40
5.4.190.0050.03612.40
5.4.180.0060.03612.39
5.4.170.0050.03612.41
5.4.160.0030.04612.40
5.4.150.0030.03912.39
5.4.140.0100.03212.08
5.4.130.0060.03512.07
5.4.120.0070.03312.03
5.4.110.0050.03612.02
5.4.100.0050.03612.02
5.4.90.0040.03712.02
5.4.80.0050.03612.02
5.4.70.0040.03512.02
5.4.60.0030.03612.02
5.4.50.0060.04012.02
5.4.40.0050.04012.01
5.4.30.0040.03712.01
5.4.20.0040.03612.00
5.4.10.0050.03812.01
5.4.00.0090.03611.50
5.3.290.0060.04612.80
5.3.280.0070.04012.71
5.3.270.0100.04512.73
5.3.260.0070.04312.71
5.3.250.0090.03612.72
5.3.240.0080.03312.72
5.3.230.0030.04512.71
5.3.220.0070.03912.68
5.3.210.0060.04812.68
5.3.200.0060.03612.68
5.3.190.0080.03512.68
5.3.180.0070.03512.68
5.3.170.0040.03712.67
5.3.160.0070.03612.67
5.3.150.0050.03712.68
5.3.140.0090.03612.66
5.3.130.0100.04312.66
5.3.120.0100.04612.66
5.3.110.0110.03812.66
5.3.100.0050.04112.15
5.3.90.0080.03612.13
5.3.80.0020.04012.12
5.3.70.0030.03912.12
5.3.60.0080.03412.10
5.3.50.0050.03712.05
5.3.40.0060.03512.05
5.3.30.0050.03512.01
5.3.20.0070.03611.79
5.3.10.0100.03111.76
5.3.00.0110.03111.74
5.2.170.0070.0289.25
5.2.160.0110.0239.25
5.2.150.0080.0309.25
5.2.140.0070.0349.25
5.2.130.0060.0289.20
5.2.120.0070.0349.21
5.2.110.0060.0289.21
5.2.100.0040.0299.21
5.2.90.0050.0349.21
5.2.80.0030.0359.20
5.2.70.0050.0319.20
5.2.60.0080.0309.16
5.2.50.0060.0329.13
5.2.40.0070.0279.10
5.2.30.0060.0329.08
5.2.20.0060.0279.07
5.2.10.0060.0278.96
5.2.00.0030.0318.82
5.1.60.0060.0218.11
5.1.50.0030.0268.10
5.1.40.0070.0228.09
5.1.30.0050.0258.43
5.1.20.0060.0268.45
5.1.10.0010.0308.18
5.1.00.0050.0278.19
5.0.50.0070.0216.66
5.0.40.0040.0186.52
5.0.30.0050.0356.33
5.0.20.0040.0206.30
5.0.10.0050.0216.28
5.0.00.0030.0306.28
4.4.90.0010.0174.78
4.4.80.0040.0154.75
4.4.70.0030.0154.76
4.4.60.0020.0164.75
4.4.50.0040.0194.77
4.4.40.0020.0304.71
4.4.30.0020.0164.76
4.4.20.0020.0154.84
4.4.10.0070.0204.84
4.4.00.0030.0244.76
4.3.110.0020.0174.67
4.3.100.0020.0154.67
4.3.90.0010.0164.63
4.3.80.0050.0274.59
4.3.70.0020.0194.63
4.3.60.0030.0164.63
4.3.50.0030.0194.63
4.3.40.0010.0254.53
4.3.30.0010.0163.30
4.3.20.0010.0163.28
4.3.10.0020.0153.24
4.3.00.0070.01343.79

preferences:
143.81 ms | 1386 KiB | 7 Q