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 "\n\n\n"; echo String::truncate('jo<i><b>n</b>as</i>', 3, '&hellip;', true); //jo<i><b>n</b></i>... echo "\n\n\n"; 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.0030.07021.13
5.6.210.0070.06720.58
5.6.200.0130.07718.18
5.6.190.0070.05020.66
5.6.180.0000.05320.77
5.6.170.0200.03720.71
5.6.160.0070.08720.47
5.6.150.0100.05318.25
5.6.140.0070.07718.24
5.6.130.0070.04018.18
5.6.120.0170.07321.06
5.6.110.0030.08020.98
5.6.100.0030.09321.15
5.6.90.0170.08020.97
5.6.80.0200.07020.54
5.6.70.4700.04020.38
5.5.350.0100.08020.35
5.5.340.0130.06018.04
5.5.330.0070.07020.31
5.5.320.0030.06320.25
5.5.310.0230.05720.19
5.5.300.0070.08018.05
5.5.290.0130.07018.01
5.5.280.0130.07720.75
5.5.270.0130.07720.77
5.5.260.0130.07020.86
5.5.250.0070.09720.70
5.5.240.0100.07020.08
5.4.450.0270.04343.90
5.4.440.0370.05343.90
5.4.430.0170.03743.84
5.4.420.0200.04743.80
5.4.410.0230.04343.79
5.4.400.0230.03043.77
5.4.390.0370.04343.77
5.4.380.0170.04718.61
5.4.370.0100.05018.62
5.4.360.0070.05318.73
5.4.350.0030.05718.48
5.4.340.0170.04318.65
5.4.320.0060.04112.52
5.4.310.0080.04412.52
5.4.300.0020.03912.51
5.4.290.0040.04012.51
5.4.280.0080.03912.41
5.4.270.0080.04112.41
5.4.260.0050.03812.41
5.4.250.0030.03912.41
5.4.240.0050.03612.40
5.4.230.0050.03812.40
5.4.220.0060.03512.40
5.4.210.0070.03512.40
5.4.200.0060.03912.40
5.4.190.0040.04512.39
5.4.180.0070.04112.39
5.4.170.0060.04912.41
5.4.160.0060.03512.40
5.4.150.0100.03312.40
5.4.140.0060.04012.09
5.4.130.0040.03712.07
5.4.120.0090.03612.03
5.4.110.0050.03912.02
5.4.100.0050.03712.02
5.4.90.0060.03512.03
5.4.80.0070.03712.02
5.4.70.0060.03512.02
5.4.60.0070.03212.02
5.4.50.0090.03812.02
5.4.40.0040.03612.01
5.4.30.0070.03512.00
5.4.20.0100.03012.01
5.4.10.0090.04012.01
5.4.00.0060.03411.49
5.3.290.0020.04312.80
5.3.280.0100.03212.71
5.3.270.0080.03712.73
5.3.260.0050.03912.72
5.3.250.0050.03712.71
5.3.240.0080.03412.72
5.3.230.0090.03512.71
5.3.220.0070.03712.68
5.3.210.0100.03812.68
5.3.200.0060.03712.68
5.3.190.0080.03512.68
5.3.180.0070.03612.68
5.3.170.0070.03512.67
5.3.160.0040.03712.67
5.3.150.0060.04012.67
5.3.140.0080.03712.66
5.3.130.0050.04012.66
5.3.120.0040.04012.66
5.3.110.0020.04312.66
5.3.100.0090.03312.14
5.3.90.0020.04012.13
5.3.80.0100.03212.12
5.3.70.0040.03812.12
5.3.60.0080.03512.10
5.3.50.0070.03512.05
5.3.40.0050.03612.05
5.3.30.0050.03512.01
5.3.20.0050.03611.79
5.3.10.0100.03011.75
5.3.00.0080.03311.74
5.2.170.0090.0299.24
5.2.160.0050.0289.25
5.2.150.0070.0339.25
5.2.140.0050.0299.24
5.2.130.0040.0309.21
5.2.120.0060.0319.20
5.2.110.0020.0329.21
5.2.100.0060.0279.20
5.2.90.0030.0309.21
5.2.80.0040.0309.21
5.2.70.0060.0319.20
5.2.60.0060.0289.16
5.2.50.0050.0319.13
5.2.40.0050.0299.10
5.2.30.0060.0279.09
5.2.20.0030.0309.07
5.2.10.0050.0278.96
5.2.00.0040.0298.82
5.1.60.0020.0258.11
5.1.50.0040.0248.10
5.1.40.0040.0248.08
5.1.30.0080.0228.44
5.1.20.0030.0278.45
5.1.10.0080.0268.18
5.1.00.0030.0268.18
5.0.50.0040.0196.66
5.0.40.0030.0196.52
5.0.30.0030.0316.33
5.0.20.0030.0316.30
5.0.10.0020.0216.28
5.0.00.0050.0286.29
4.4.90.0010.0214.78
4.4.80.0010.0174.75
4.4.70.0030.0274.75
4.4.60.0030.0154.76
4.4.50.0030.0154.77
4.4.40.0000.0274.71
4.4.30.0020.0164.76
4.4.20.0030.0154.84
4.4.10.0050.0254.85
4.4.00.0030.0304.76
4.3.110.0030.0154.67
4.3.100.0000.0204.66
4.3.90.0020.0174.63
4.3.80.0040.0344.58
4.3.70.0030.0214.63
4.3.60.0010.0164.63
4.3.50.0020.0164.63
4.3.40.0060.0264.54
4.3.30.0020.0163.30
4.3.20.0020.0163.28
4.3.10.0010.0173.23
4.3.00.0030.01743.77

preferences:
149.83 ms | 1394 KiB | 7 Q