$mystring = "this is the text I would like to truncate";
// Pass your variable to the function
$mystring = truncate($mystring);
// Truncated tring printed out;
echo $mystring;
//truncate text function
public function truncate($text) {
//specify number fo characters to shorten by
$chars = 25;
$text = $text." ";
$text = substr($text,0,$chars);
$text = substr($text,0,strrpos($text,' '));
$text = $text."...";
return $text;
}