View Full Version : PHP MySQL How to limit lines?
tilight
Wed 10th Nov '04, 11:33pm
$limittext[$n] = substr($newsitem["6"], 0, 200) . " ...";
Thats how I limited the chars, but now I need to limit the lines or else my table will be uneven. How can I limit lines?
Thanks
Stadler
Thu 11th Nov '04, 9:35am
You could try the following:
<?php
$maxlines = 5;
// see http://de2.php.net/manual/en/function.nl2br.php
$newtext = nl2br($text);
// explode the string 'seperated' by <br /> (or <br> for PHP < 4.0.5),
// but limited to the first $maxlines lines
$lines = preg_split('#<br( /)?>#', $newtext, $maxlines);
// stick them back together
$newtext = implode('<br />', $lines);
?>
tilight
Thu 11th Nov '04, 8:23pm
OMG, your awsome! Thanks soo much!
Hmm I tried to add it myself, but its not changing anything, could you help further?
$news = mysql_query("select thread.threadid,thread.title,thread.replycount,thr ead.postusername,thread.dateline,post.postid,post. pagetext from thread,post where thread.forumid IN (2,7) and post.postid=thread.firstpostid group by thread.firstpostid order by threadid desc limit 4;");
$maxlinesn = 2;
$n = 0;
while($newsitem = mysql_fetch_row($news)){
$n++;
$newstitle[$n]=$newsitem["1"];
$newsthread[$n]=$newsitem["5"];
$limittext[$n] = substr($newsitem["6"], 0, 200) . " ...";
$newstext[$n]=parse_bbcode($limittext[$n]);
$newsavatar[$n]=$newsitem["7"];
$newtext = nl2br($limittext[$n]);
$lines = preg_split('#<br( /)?>#', $newtext, $maxlinesn);
$newtext = implode('<br />', $lines);
}
vBulletin® v3.8.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.