note 53885 added to function.explode

From: Date: Thu, 16 Jun 2005 05:27:14 +0000
Subject: note 53885 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-90502@lists.php.net to get a copy of this message
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; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53885 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53885&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53885&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53885&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53885&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+53885&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53885&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53885&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90502) next »