note 84103 deleted from function.substr by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 11:01:53 +0000 |
| Subject: | note 84103 deleted from function.substr by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197035@lists.php.net to get a copy of this message | ||
Note Submitter: svihel
----
joao dot martins at plako dot net
26-Mar-2008 09:14
ben at enemy dot dk
10-Feb-2008 05:48
Updated function. The previous one will return empty value if the $string has no letter spaces. This
is usefull if some of your strings have only one word.
<?php
function cutText($string, $setlength) {
$length = $setlength;
if($length<strlen($string)){
while (($string{$length} != " ") AND ($length > 0)) {
$length--;
}
if ($length == 0) return substr($string, 0, $setlength);
else return substr($string, 0, $length);
}else return $string;
}
?>