/ Published in: PHP
URL: http://www.undolog.com/2008/09/21/very-short-snippet-php-word-cut/
Word Cut Function
Expand |
Embed | Plain Text
Comments
Subscribe to comments
You need to login to post a comment.
gfazioli on 09/21/08
3 people have marked this snippet as a favorite
URL: http://www.undolog.com/2008/09/21/very-short-snippet-php-word-cut/
Word Cut Function
Subscribe to comments
You need to login to post a comment.
In my opinion this is a better solution, both because you avoid the loop but it also takes into consideration that the content might be shorter than the limit:
$contentTemp = explode(' ', $content); if (count($contentTemp) > $limit) { $content = implode(' ', array_slice($contentTemp, 0, $limit)) . '...'; } return $content;
$cut=explode("\n",wordwrap($content,250)); return $cut[0].(count($cut)>1 ? '...' : '');