Takes a string and truncates it to the last word at string length $MAX, adding periods at the end of the text.
<?php

function truncate_string($details,$max)
{
    if(strlen($details)>$max)
    {
        $details = substr($details,0,$max);
        $i = strrpos($details," ");
        $details = substr($details,0,$i);
        $details = $details." ..... ";
    }
    return $details;
}

?>
Example:
<?php

$text = truncate_string("hello there. This is a long string",19);

?>

returns

hello there. This .....