Jump to content

Recommended Posts

Good day to you all,

            Here I come again with a piece of code which reach a txt file and return the text, it also convert the "\n" into "<br>".

 

Here it is :

 

function drawList($list)
{     
      $thelist = '';         
      foreach($list as $file=>$string)
      {

        $lines = nl2br($string);
              $thelist .= '<b class="b1h"></b><b class="b2h"></b><b class="b3h"></b><b class="b4h"></b>';
              $thelist .= '<div class="headh">';
              $thelist .= '<b>'.$file.'</b>';
              $thelist .= '</div>';              
              $thelist .= '<div class="contenth"><div class="text">';
              $thelist .= $lines.'<br/>';
              $thelist .= '</div>';
              $thelist .= '</div>';
              $thelist .= '<b class="b4bh"></b><b class="b3bh"></b><b class="b2bh"></b><b class="b1h"></b><br/>';
    }
    return $thelist;
        
}

 

 

How can I make $lines have alternate row color ?

 

Thanks !

Link to comment
https://forums.phpfreaks.com/topic/133029-alternate-row-color/
Share on other sites

function drawList($list)
{     
$color1 = "#cccccc";
$color2 = "#ffffff";
$color = $color1;

      $thelist = '';         
      foreach($list as $file=>$string)
      {

        $lines = nl2br($string);
              $thelist .= '<b class="b1h"></b><b class="b2h"></b><b class="b3h"></b><b class="b4h"></b>';
              $thelist .= '<div class="headh">';
              $thelist .= '<b>'.$file.'</b>';
              $thelist .= '</div>';              
              $thelist .= '<div class="contenth" style="background-color:'.$color.'"><div class="text">';
              $thelist .= $lines.'<br/>';
              $thelist .= '</div>';
              $thelist .= '</div>';
              $thelist .= '<b class="b4bh"></b><b class="b3bh"></b><b class="b2bh"></b><b class="b1h"></b><br/>';
$color = ($color == $color1 ? $color2 : $color1);
    }
    return $thelist;
        
}

 

Try that out.

Link to comment
https://forums.phpfreaks.com/topic/133029-alternate-row-color/#findComment-691901
Share on other sites

Than ya wud want replace nl2br to maybe something like

 
$lines=explode("\n",$lines);
$count=0;
$color[0] = "#cccccc";
$color[1] = "#ffffff";
foreach($lines as $key=>$line)
{  $lines[$key]="<div class=\"contentalt\" style=\"background-color:{$color[$count]}\">{$line}</div>"; $count=(++$count & 1); }
$lines=implode('<br>',$lines)

Link to comment
https://forums.phpfreaks.com/topic/133029-alternate-row-color/#findComment-692077
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.