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
https://forums.phpfreaks.com/topic/205121-how-to-add-trailing-periods-in-an-array/
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'];
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.