note 33736 added to function.substr-replace

From: Date: Sat, 05 Jul 2003 22:36:58 +0000
Subject: note 33736 added to function.substr-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-51570@lists.php.net to get a copy of this message
Here is a simple function to shorten a string and add an ellipsis <?php /** * truncate() Simple function to shorten a string and add an ellipsis * * @param string $string Origonal string * @param integer $max Maximum length * @param string $rep Replace with... (Default = '' - No elipsis -) * @return string * @author David Duong **/ function truncate ($string, $max = 50, $rep = '') { $leave = $max - strlen ($rep); return substr_replace($string, $rep, $leave); } echo truncate ('akfhslakdhglksjdgh', 10, '...'); // Returns akfhsla... (10 chrs) ?> ---- Manual Page -- http://www.php.net/manual/en/function.substr-replace.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33736 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33736&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33736&report=yes

« previous php.notes (#51570) next »