note 53876 added to function.explode

From: Date: Wed, 15 Jun 2005 19:44:27 +0000
Subject: note 53876 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-90492@lists.php.net to get a copy of this message
Here is a modified version of the function below. Rather than limit by number of words, this should limit by number of characters. The function will cut off the sentence to the preceding word taking into consideration the ending "ellipsis". function charLimit($string, $length = 25, $ellipsis = "...") { $words = explode(' ', $string); $curindex = 0; $wcount = 0; foreach($words as $value){ $wcount += strlen($value); 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+53876 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53876&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53876&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53876&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53876&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53876&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53876&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90492) next »