3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function cut_off_string_maybe($string, $limit) { if (mb_strlen($string) <= $limit) return htmlspecialchars($string); else return trim(htmlspecialchars(mb_substr($string, 0, $limit, 'UTF-8'))) . '...'; } echo cut_off_string_maybe("This is a test",4); echo cut_off_string_maybe("Whats your problem",4); echo cut_off_string_maybe("OK this is it",5);
Output for 4.3.0 - 7.1.0
This...What...OK th...