Announcement

Collapse
No announcement yet.

PHP MySQL How to limit lines?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP MySQL How to limit lines?

    $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

  • #2
    You could try the following:
    PHP Code:
    <?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);
     
     
    ?>
    Hints & Tips:
    [[vB3] More Spiders / Indexers / Archives for vB3 - list]|[List of one-time-emails to ban]


    http://sfx-images.mozilla.org/affili...efox_80x15.png

    Comment


    • #3
      OMG, your awsome! Thanks soo much!

      Hmm I tried to add it myself, but its not changing anything, could you help further?

      Code:
      $news = mysql_query("select thread.threadid,thread.title,thread.replycount,thread.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);
      }
      Last edited by tilight; Thu 11th Nov '04, 4:30pm.

      Comment

      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
      Working...
      X