note 82530 deleted from function.strlen by hholzgra

From: Date: Thu, 02 Aug 2012 12:15:26 +0000
Subject: note 82530 deleted from function.strlen by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189617@lists.php.net to get a copy of this message
Note Submitter: radu_keepwalking at yahoo dot com ---- Another way to preview a text with or without html tags, and end not cut in a middle of a word. <?php function preview_text($TEXT, $LIMIT, $TAGS = 0) { // TRIM TEXT $TEXT = trim($TEXT); // STRIP TAGS IF PREVIEW IS WITHOUT HTML if ($TAGS == 0) $TEXT = preg_replace('/\s\s+/', ' ', strip_tags($TEXT)); // IF STRLEN IS SMALLER THAN LIMIT RETURN if (strlen($TEXT) < $LIMIT) return $TEXT; if ($TAGS == 0) return substr($TEXT, 0, $LIMIT) . " ..."; else { $COUNTER = 0; for ($i = 0; $i<= strlen($TEXT); $i++) { if ($TEXT{$i} == "<") $STOP = 1; if ($STOP != 1) { $COUNTER++; } if ($TEXT{$i} == ">") $STOP = 0; $RETURN .= $TEXT{$i}; if ($COUNTER >= $LIMIT && $TEXT{$i} == " ") break; } return $RETURN . "..."; } } ?>

« previous php.notes (#189617) next »