note 76583 deleted from function.substr-replace by nlopess

From: Date: Sat, 21 Jul 2007 19:39:31 +0000
Subject: note 76583 deleted from function.substr-replace by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-128802@lists.php.net to get a copy of this message
Note Submitter: jstgermain at methodcomptech dot com ---- I am using this to truncate strings being pulled from the MySQL database for a news column located on the left of a clients site. you can visit http://www.azbizfilings.com to see it in action. below is just the important part of the code that you should be able to determine what has been done. <?php function trunc($phrase) { $max_words = 10; $phrase_array = explode(' ',$phrase); if(count($phrase_array) > $max_words && $max_words > 0) $phrase = implode(' ',array_slice($phrase_array, 0, $max_words)).'...'; return $phrase; } echo '<p>'.trunc($row['content']).'</p> <p align="right"> <a href="'.$home.'news.php?view=news&sID='.$sID.'">more</a> &raquo; </p>'; ?>

« previous php.notes (#128802) next »