Mega Code Archive
Truncating Text on Word Boundaries
$max) {
$max -= strlen($moretext);
$string = strrev(strstr(strrev(substr($string, 0, $max)), ' '));
$string .= $moretext;
}
return $string;
}
$str = 'This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.';
$values = truncate_text_nicely($str, 20, '...');
echo "{$values}
";
?>