note 95685 deleted from function.str-word-count by danbrown
| From: | danbrown@php.net | Date: | Fri, 15 Jan 2010 20:23:18 +0000 |
| Subject: | note 95685 deleted from function.str-word-count by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-165012@lists.php.net to get a copy of this message | ||
Note Submitter: PHPimpin
----
I fixed pdziok's version.
function WordLimiter($text,$limit=20){
$explode = str_word_count($text,1);
$string = '';
$dots = '...';
if(count($explode) <= $limit){
$dots = '';
foreach(array_keys($explode) as $key){
$string .= $explode[$key]." ";
}
} else {
for($i=0;$i<=$limit;$i++){
$string .= $explode[$i]." ";
}
}
if ($dots) {
$string = substr($string, 0, strlen($string));
}
return $string.$dots;
}