3v4l.org

run code in 300+ PHP versions simultaneously
<?php function truncate($text, $max) { if (strlen($text) >= $max) { $text = ereg_replace("<[^>]*>", "", $text); $text = substr($text, 0, $max); $position = strrpos($text, " "); $text = substr($text, 0, $position)."..."; } return $text; } echo truncate('Lorem ipsum dolor <span>sit</span> amet !', 25); ?>

preferences:
40.43 ms | 402 KiB | 5 Q