View Full Version : $thread[title]
K33nny
04-17-2004, 03:17 AM
I would like to put a max character cap on $thread[title] for forumdisplay.php.
Here is my idea but it did not work.
$maxthreadtitle = 45;
$title = $ar[$thread[threadid]][title];
$maxchars = $maxthreadtitle;
if (strlen($title)>$maxchars-1)
{
$spacepos = strpos($title." "," ",$maxchars);
if ($spacepos!=0)
{
$title = substr($title ,0,$spacepos)."...";
}
}
K33nny
04-17-2004, 09:15 AM
Come on, someone help me! :devious:
Is easier then you think, use:
$trimmed_title = fetch_trimmed_title($thread['threadid'], 45);
You are done. ;)
Boofo
04-17-2004, 07:42 PM
Isn't that vB3 code you posted, Floren? Will that wrok with vB2? ;)
K33nny
04-17-2004, 08:41 PM
Where would I put your code TECK?
Sorry, Bob is right, this is for VB3.. I didn't realised we are in VB2 section.
Well, look at this function in vb3 functions.php and use the same approach...
K33nny
04-18-2004, 11:35 PM
None of this has really helped me in anyway, thanks for trying I guess.
None of this has really helped me in anyway, thanks for trying I guess.
Well, it's helping you. All you have to do is look at the VB3 function I mentioned and you will be able to make it working.
Let me know if you have any other questions regarding the function.
K33nny
04-20-2004, 01:08 AM
Well, it's helping you. All you have to do is look at the VB3 function I mentioned and you will be able to make it working.
Let me know if you have any other questions regarding the function.
I'm not sure what function to look at or the file rather.
K33nny
04-20-2004, 06:21 AM
function fetch_trimmed_title($title, $chars = -1)
{
global $vboptions;
if ($chars == -1)
{
$chars = $vboptions['lastthreadchars'];
}
if ($chars)
{
// limit to 10 lines (\n{240}1234567890 does weird things to the thread preview)
$titlearr = preg_split('#(\r\n|\n|\r)#', $title);
$title = '';
$i = 0;
foreach ($titlearr AS $key)
{
$title .= "$key\n";
$i++;
if ($i >= 10)
{
break;
}
}
$title = trim($title);
unset($titlearr);
if (strlen($title) > $chars)
{
// trim text to specified char length, then trim after last space to avoid half-words
return substr($title, 0, strrpos(substr($title, 0, $chars), ' ')) . '...';
}
else
{
return $title;
}
}
else
{
return $title;
}
}
TECK do you realize how confusing that is for me?
Meltdown
04-20-2004, 01:50 PM
Why dont you just open the 'newthread' template and change the 'maxlength="85" value of the title input to maxlength="45".
filburt1
04-20-2004, 02:02 PM
Why dont you just open the 'newthread' template and change the 'maxlength="85" value of the title input to maxlength="45".
A user interface hack (hack in the negative sense) is never preferable to a cleaner system.
You can simply change the VARCHAR size of the title column in the thread table to the maximum size you want, which will definitely restrict character length. Combined with a maxlength attribute, it will work perfectly.
K33nny
04-20-2004, 08:50 PM
Meltdown: Because I only want to cut the title off the thread title off during threadlist process. Also, my forums have been online for 3 years, with 270000 posts... so setting the cap now does very little. I have a certain cell width I want the titles to fit into so by cutting it off, it helps keep it within the cell.
filburt1: If I limit the VARCHAR size of the title column is it just going to randomly cut it off?
K33nny
04-23-2004, 05:10 PM
Will someone please help me? I have not been able to port the vb3 stuff over to vb2.
Ok. But keep in mind that I don't use anymore VB2... :)
However, the code posted below will work perfectly for you.
Find the $thread['title'] (I don't remember the function name, sorry) and below, add:
if (strlen($thread['title']) > 45)
{
$thread['title'] = substr($thread['title'], 0, 42) . '...';
}
That will replace the hole title, for example:
"The white dog jumps over the red deer to catch the yellow ball!"
with:
"The white dog jumps over the red deer to catch the yello..." (45 chars limit).
Sorry, but if other VB2 users know what is the function I talk about, they will tell you exacly where to place the code mentioned above.
As you see, is pretty easy.
No need to complicate your life with complex code, simple will do just great. :)
Regards,
Floren.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.