Need a little code
I'm using this code to display forum thread titles on a custom vb page:
<script type="text/javascript" src="external.php?forumids=111,112,113,114,115,133 ,148,154&type=js"></script>
<script language="" type="text/javascript">
<!--
for (x = 0; x < 3; x++)
{
document.writeln("<a href=\"showthread.php?t="+threads[x].threadid+"\">");
document.writeln("<b>"+threads[x].title+"</b><br />");
document.writeln("</a>");
document.writeln("Posted "+threads[x].threaddate+" at "+threads[x].threadtime+" by "+threads[x].poster+"<br />");
}
//-->
</script>
I'm trying to figure out how to limit the number of characters that are displayed in the title.
document.writeln("<b>"+threads[x].title+"</b><br />");
I tried inserting this code inside the javascript but I can't seem to get it to work
<?php
$len = 30;
if (strlen($thread['title']) > $len) {
$thread['title'] = substr($thread['title'],0,$len);
$thread['title'] .= "...";
} else {
$thread['title'] = $thread['title'];
}
?>
Ideally I would like to limit the character length of threads.title and append a ... when it gets cut off.
Any coders out there have a solution for me?
Thanks
|