note 69947 deleted from function.strpos by bobby

From: Date: Wed, 27 Sep 2006 15:48:40 +0000
Subject: note 69947 deleted from function.strpos by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-117738@lists.php.net to get a copy of this message
Note Submitter: webmaster at matericosweb dot com ---- Jaxolotl, (bug fixed, sorry) This Simple function allows you to reduce a long text to an smaller one, for example when you use articles text previews. The cool feature is that it doesn't cuts the words, just search for the first white space after the assigned limit and cuts the phrase there. <?php ############################################### TEXT REDUCE function reduce_text($string){ //The Strip_tags() is used to prevent tables or any other tag to be cut unproperly. $string = strip_tags($string); //Search the end of a word after [, int offset] and set the result as limit $limit = @strpos($string, " ",200); if($limit){ // if string is larger than [, int offset] //Use $limit to replace width ...Text return substr_replace($string, "... <em>continue</em>",$limit); //Change ... <em>continue</em> with anithing you need. } else{ //just return text without html tags return $string; } } ?>

« previous php.notes (#117738) next »