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...
Output for 5.0.0 - 5.0.5, 5.1.1 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28
jo<&hellip;<hr>jo<i><b>n</b></i>&hellip;<hr>jo<i><b>n</b></i>&hellip;
Output for 5.1.0
Fatal error: fatal flex scanner internal error--end of buffer missed in /in/05N38 on line 31
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/05N38 on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/05N38 on line 6
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/05N38 on line 6
Process exited with code 255.

preferences:
241.36 ms | 1395 KiB | 200 Q