Page 2 of 2

Posted: Thu May 15, 2003 2:59 am
by twigletmac
First off, you don't need both:

Code: Select all

$thread_title = $out['title']; 
      if (strlen($thread_title) == 20) { 
      $thread_title .=  '...'; 
      }
and

Code: Select all

$maxlength = 20; 
      if (strlen($thread_title) > $maxlength){ 
      $truncatedtext = substr($thread_title, 0, $maxlength) . "..."; 
      } else { 
      $truncatedtext = $thread_title; 
      }

If you want you can amalgamate them into:

Code: Select all

$thread_title = $out['title'];
$maxlength = 20;
if (strlen($thread_title) == $maxlength) {
    $thread_title .= '...';
}
Then after than I would put:

Code: Select all

echo 'The truncated text is: '.$thread_title;
as a way to see what it looks like.

Mac