Here's what i use. It doesn't leave any chopped word on the end.
Very handy for long strings..
<?php
function do_TrimString($string, $MaxSTRLEN = null) {
if ($MaxSTRLEN == null) { global $MaxSTRLEN; }
if (strlen($string) > $MaxSTRLEN) {
$string = substr($string, 0, $MaxSTRLEN);
$end = strrpos($string, ' ');
if ($end === false) {
$end = $MaxSTRLEN;
}
$string = substr($string, 0, $end) . '...';
}
return $string;
}
?>