note 82063 added to function.substr
| From: | joao dot martins at plako dot net | Date: | Wed, 26 Mar 2008 13:14:34 +0000 |
| Subject: | note 82063 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137596@lists.php.net to get a copy of this message | ||
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;
}
----
Server IP: 81.92.200.26
Probable Submitter: 82.155.123.204
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- https://master.php.net/note/edit/82063
Del: integrated -- https://master.php.net/note/delete/82063/integrated
Del: useless -- https://master.php.net/note/delete/82063/useless
Del: bad code -- https://master.php.net/note/delete/82063/bad+code
Del: spam -- https://master.php.net/note/delete/82063/spam
Del: non-english -- https://master.php.net/note/delete/82063/non-english
Del: in docs -- https://master.php.net/note/delete/82063/in+docs
Del: other reasons-- https://master.php.net/note/delete/82063
Reject -- https://master.php.net/note/reject/82063
Search -- https://master.php.net/manage/user-notes.php