3v4l.org

run code in 300+ PHP versions simultaneously
<?php function str_truncat($string, $nbrchar = 50, $charsfin = "", $addstrfin = "...") { if($charsfin == "" && strlen(strip_tags($string)) < $nbrchar) { $stringtruncat = strip_tags($string); } else { $nbr = ($nbrchar)/250; $addchars = ""; if($nbr > 1) { for($i = 0;$i < (int)$nbr;$i++) { $nbrchar -= 250; $addchars .= ".{250}"; } } $addchars .= ".{".$nbrchar."}"; $str1 = preg_replace("(\[+[a-z0-9]+\]{1,2})", "", str_replace("\n"," ",strip_tags($string))); $str2 = preg_replace("(\[+[a-zA-Z:0-9]+[ |]([^\]]+)*\]+)", "\\1 ", $str1); $preg = "/^(".$addchars.($charsfin?"[^".$charsfin."]*":"").").*$/"; $str3 = preg_replace($preg, "\\1".$addstrfin, $str2); $stringtruncat = preg_replace("/ ".str_replace(".", "\.", $addstrfin)."$/", $addstrfin, $str3); } return htmlspecialchars($stringtruncat, ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'); } $var = "LG 47LA640S859 € dont 8 &euro d'écocontribution"; $var = html_entity_decode($var, ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'); $var = str_truncat($var); echo $var;
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
LG 47LA640S859 € dont 8 &amp;euro d'écocontribution...
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Notice: Use of undefined constant ENT_HTML401 - assumed 'ENT_HTML401' in /in/OHeRX on line 28 Notice: Use of undefined constant ENT_HTML401 - assumed 'ENT_HTML401' in /in/OHeRX on line 24 LG 47LA640S859 € dont 8 &amp;euro d'écocontribution...
Output for 4.3.0 - 4.3.1
Notice: Use of undefined constant ENT_HTML401 - assumed 'ENT_HTML401' in /in/OHeRX on line 28
Process exited with code 139.

preferences:
246.58 ms | 401 KiB | 456 Q