note 82063 deleted from function.substr by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Nov 2008 20:13:56 +0000 |
| Subject: | note 82063 deleted from function.substr by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147190@lists.php.net to get a copy of this message | ||
Note Submitter: joao dot martins at plako dot net
----
ben at enemy dot dk
10-Feb-2008 05:48
The function he wrote to cut text whithout cutting in middle of words, doesn't work if $lenght
is smaller than $string size..
Just add a simple test and it works perfect for listing texts with a maximum chars:
function cutText($string, $length) {
if($length<strlen($string)){
while ($string{$length} != " ") {
$length--;
}
return substr($string, 0, $length);
}else return $string;
}