Jump to content

How to add trailing periods in an array?


Travis959

Recommended Posts

Hey guys, I have a script that is used to showcase the newest forum (vbulletin) threads on an external page but I can't figure out a way to add trailing periods to it if the array is over a certain amount of characters.

 

function output_NewestReplies($a = 5,$f = ""){
global $db, $Data;

// Define amount to show
$Amount = ($a)? intval($a) : 5;

// Define Forum(s) To Pull From
$Forums = ($f)? $f: '';
$SQL    = '';

	if($Forums){
	$SQL = " where forumid in({$Forums})";
	}

// Load Template
$Template = LoadTemplate("newest_threads.html");

// Collect Data
$NewestReplies = $db->query("select * from ".TABLE_PREFIX."thread{$SQL} order by lastpost desc limit 0,$Amount");

	while($Thread = $db->fetch_array($NewestReplies)){	
	$Data .= ParseTemplate($Template,
						array(
							'threadid'     => $Thread['threadid'],
							'threadname'   => $Thread['title'],
							'postuserid'   => $Thread['postuserid'],
							'postusername' => $Thread['postusername'],
							'replies'      => vb_number_format($Thread['replycount']),
							'views'        => vb_number_format($Thread['views']),
							'lastposter'   => $Thread['lastposter'],
						)
		);	
	}

doOutput();
}

 

That's the function to call for new replies, and I'm trying to add trailing periods to " $Thread['title']" if "$Thread['title']" exceeds a certain character limit. Any ideas?

 

Thanks!

Link to comment
Share on other sites

I'm too tired to write up the actual code but I'm sure you could do it with strlen() and substr()

 

Actually, since you gave the vars at the bottom of your post.

$characterlimit = 25;
if(strlen($Thread['title']) > $characterlimit){
     echo substr($Thread['title'], 0, $characterlimit) . '...';
}else{
     echo $Thread['title'];
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.