Travis959 Posted June 18, 2010 Share Posted June 18, 2010 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! Quote Link to comment Share on other sites More sharing options...
Soldier Jane Posted June 18, 2010 Share Posted June 18, 2010 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']; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.