note 82530 added to function.strlen

From: Date: Tue, 15 Apr 2008 11:37:18 +0000
Subject: note 82530 added to function.strlen
Groups: php.notes 
Request: Send a blank email to php-notes+get-138328@lists.php.net to get a copy of this message
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 . "..."; } } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 86.104.78.217 ---- Manual Page -- http://www.php.net/manual/en/function.strlen.php Edit -- https://master.php.net/note/edit/82530 Del: integrated -- https://master.php.net/note/delete/82530/integrated Del: useless -- https://master.php.net/note/delete/82530/useless Del: bad code -- https://master.php.net/note/delete/82530/bad+code Del: spam -- https://master.php.net/note/delete/82530/spam Del: non-english -- https://master.php.net/note/delete/82530/non-english Del: in docs -- https://master.php.net/note/delete/82530/in+docs Del: other reasons-- https://master.php.net/note/delete/82530 Reject -- https://master.php.net/note/reject/82530 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138328) next »