Re: Display only so many characters

From: Date: Tue, 05 Nov 2002 17:48:55 +0000
Subject: Re: Display only so many characters
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-122809@lists.php.net to get a copy of this message
Hi, Wednesday, November 6, 2002, 3:21:03 AM, you wrote: S> I've seen this on a lot of news sites and such. How can I display only so many S> characters, then put a "..." to show that it's continued? S> Thanks, S> Stephen Craton S> http://www.melchior.us S> "Life is a gift from God. Wasting it is like destroying your favorite item you received S> from the person you love most." -- www.melchior.us Here is one way that cuts at a space <? $maxchar = 30; $text = "I've seen this on a lot of news sites and such. How can I display only so many characters"; $len = strlen($text); if($len > $maxchar){ $t = substr($text,0,$maxchar); $lspace = strrpos($t,' '); if(!($lspace === false)&& $lspace > 0){ $t = substr($t,0,$lspace); for($x=$lspace;$x < ($maxchar+2);$x++){ $t .= '.'; } } $text = $t; } echo $text.'<br>'; -- regards, Tom

« previous php.general (#122809) next »