Maarten’s Posterous

Internet Development 
« Back to blog

PHP Limit Words Function

This function will shorten a paragraph, but will not cut in the middle of a word...

function limit_words($string, $word_limit) {

    $words = explode(' ', $string, ($word_limit + 1));
    array_pop($words);
    return implode(' ', $words);
}

Comments (0)

Leave a comment...

 
To leave a comment on this posterous, please login by clicking one of the following.
Posterous-login     Connect     twitter