Use this to get a summary for a blog article, for example : it returns a tag-stripped substring, cut at the end of the last entire word, appended with ellipses if necessary.

function getSummary($text, $length = 150)
{
    $text = trim(preg_replace('~(\s+)~', ' ', strip_tags($text)));
    if (strlen($text) > $length)
    {
        $cut = substr($text, 0, $length);
        if (substr($text, $length, 1) != ' ')
            $cut = substr($cut, 0, strrpos($cut, ' '));
        $text = $cut.'...';
    }
    return $text;
}