tronca la stringa passata della lunghezza desiderata preservando le parole #PHP #TOOLS #STRINGHE #TRUNCATE
<?php
//truncate a string only at a whitespace (by nogdog)
function truncate_str($text, $length) {
$length = abs((int)$length);
if(strlen($text) > $length) {
$text = preg_replace("/^(.{1,$length})(\s.*|$)/s", '\\1...', $text);
}
return($text);
}
?>