Yes. Has been posted here before. I use this
PHP Code:
/*jesus at home dot com
03-Apr-2003 08:53
How to make a nice trim of text without break words in the middle :*/
$maxTextLenght=125;
$aspace=" ";
if(strlen($text) > $maxTextLenght ) {
$text = substr(trim($text),0,$maxTextLenght);
$text = substr($text,0,strlen($text)-strpos(strrev($text),$aspace));
$text = $text.'...';
}
So you cut of, the run a reverse search for a space and do a substr with that is number of characters.
Of course, when i pull it from a db, i do the initial chopping of with sql
PHP Code:
sql="select left(variable, 125) as variable from table";
...
$aspace=" ";
if(strlen($text) > $maxTextLenght ) {
$text = substr($text,0,strlen($text)-strpos(strrev($text),$aspace));
$text = $text.'...';
}