note 92020 deleted from function.str-word-count by danbrown
| From: | danbrown@php.net | Date: | Fri, 31 Aug 2012 16:25:02 +0000 |
| Subject: | note 92020 deleted from function.str-word-count by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190360@lists.php.net to get a copy of this message | ||
Note Submitter: pdziok at gmail dot com
----
I like your function eanimator but it got a little mistake - before the dots it putted another
space.
This is a version with "bug" repaired:
<?php
function WordLimiter($text,$limit=20){
$explode = explode(' ',$text);
$string = '';
$dots = '...';
if(count($explode) <= $limit){
$dots = '';
}
for($i=0;$i<$limit;$i++){
$string .= $explode[$i]." ";
}
if ($dots) {
$string = substr($string, 0, strlen($string));
}
return $string.$dots;
}
?>