note 21381 added to function.wordwrap

From: Date: Fri, 10 May 2002 18:25:13 +0000
Subject: note 21381 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-30431@lists.php.net to get a copy of this message
Hello, If you nee a function that limits a text to a certain number of characters, but it should always keep the whole words, try this : function limit_text($text,$maxchar){ $split=explode(" ",$text); $i=0; while(TRUE){ $len=(strlen($newtext)+strlen($split[$i])); if($len>$maxchar){ break; }else{ $newtext=$newtext." ".$split[$i]; $i++; } } return $newtext; } -- http://www.php.net/manual/en/function.wordwrap.php http://master.php.net/manage/user-notes.php?action=edit+21381 http://master.php.net/manage/user-notes.php?action=delete+21381 http://master.php.net/manage/user-notes.php?action=reject+21381

« previous php.notes (#30431) next »