3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function truncate($text, $max) { if (strlen($text) >= $max) { $text = preg_replace("#<[^>]*>#", "", $text); $text = substr($text, 0, $max); $position = strrpos($text, " "); $text = substr($text, 0, $position)."..."; } return $text; } echo truncate('Lorem ipsum dolor <strong>sit</strong> amet !', 25); ?>
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Lorem ipsum dolor sit...