View Full Version : how to limit number of words from database but if showing all don't have a more link

02-09-2009, 10:55 PM
Hi I have a news script that I built and I have a repeat of the news and I know how to limit the number of characters using this function:

function TrimLength($str, $len, $word) {
$end = "";
if (strlen($str) > $len) $end = "...";
$str = substr($str, 0, $len);
if ($word) $str = substr($str,0,strrpos($str," ")+1);
return $str.$end;

and show it:

echo TrimLength($row['art_description'], 100, true);

But if the news section is showing all of it I don't want to show the more link and visa versa if there is more to come from the database show the more link.
Is this possible.
I use this in the form:

(strlen ($_POST['art_description']) > 501) {
$error['art_description'] = 'Your description is too long, please do not submit more then 500 characters';

So I figure there must be a way to strlen but then how to have the conditional link.

Hope you understand.