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 
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 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


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to