note 23897 deleted from function.strlen by dams

From: Date: Wed, 31 Jul 2002 19:09:51 +0000
Subject: note 23897 deleted from function.strlen by dams
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-34066@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

« previous php.notes (#34066) next »