note 53885 deleted from function.explode by bjori

From: Date: Mon, 25 Sep 2006 08:09:26 +0000
Subject: note 53885 deleted from function.explode by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-117585@lists.php.net to get a copy of this message
Note Submitter: contact_trieu at hotmail dot com ---- Sorry, this is a change to the function I previously submitted to limit a sentence by chars. This accounts for spaces, whereas the previous one I submitted does not. Again, this function is a modified version of other function mentioned previously. <?php function charLimit($string, $length = 25, $ellipsis = "...") { $words = explode(' ', $string); $curindex = 0; $wcount = 0; foreach($words as $value){ $wcount += strlen($value)+1; if($wcount>$length-strlen($ellipsis)){ break; } $curindex++; } return implode(' ', array_slice($words, 0, $curindex)) . $ellipsis; } ?>

« previous php.notes (#117585) next »