note 21381 deleted from function.wordwrap by danbrown

From: Date: Sun, 17 May 2009 18:39:42 +0000
Subject: note 21381 deleted from function.wordwrap by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155160@lists.php.net to get a copy of this message
Note Submitter: lorang at e-connect dot lu ---- 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; }

« previous php.notes (#155160) next »