note 23897 added to function.strlen

From: Date: Wed, 31 Jul 2002 08:23:18 +0000
Subject: note 23897 added to function.strlen
Groups: php.notes 
Request: Send a blank email to php-notes+get-34039@lists.php.net to get a copy of this message
This is another example function that will determine the length of a string, then format it accordingly. In this case, if the string is over 50 characters, it will add 3 dots behind indicating more text is behind it. This snippet would be useful on a news site, where a "more" link could be used. <? $text = "The quick brown fox jumped over the lazy dog"; $length = strlen($text); if($length >=50) { $text = substr("$text", 0, 50); echo "$text...<br><a href=>More</a>"; } else { echo "$text"; } ?> Enjoy, Tyler Brunkhorst -- http://www.php.net/manual/en/function.strlen.php http://master.php.net/manage/user-notes.php?action=edit+23897 http://master.php.net/manage/user-notes.php?action=delete+23897 http://master.php.net/manage/user-notes.php?action=reject+23897

« previous php.notes (#34039) next »