Peuplarchie Posted November 17, 2008 Share Posted November 17, 2008 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 ! Quote Link to comment https://forums.phpfreaks.com/topic/133029-alternate-row-color/ Share on other sites More sharing options...
JasonLewis Posted November 17, 2008 Share Posted November 17, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/133029-alternate-row-color/#findComment-691901 Share on other sites More sharing options...
Peuplarchie Posted November 17, 2008 Author Share Posted November 17, 2008 Thanks, but my problem is that I want to have each line within $lines to to be alternative row color. Not each $line being alternative row color. Quote Link to comment https://forums.phpfreaks.com/topic/133029-alternate-row-color/#findComment-691905 Share on other sites More sharing options...
ddrudik Posted November 17, 2008 Share Posted November 17, 2008 Peuplarchie, it would be best to show what's in $lines if you would like a suggestion on how to change it's background color. Quote Link to comment https://forums.phpfreaks.com/topic/133029-alternate-row-color/#findComment-691991 Share on other sites More sharing options...
Peuplarchie Posted November 17, 2008 Author Share Posted November 17, 2008 it is just the content of a txt file Quote Link to comment https://forums.phpfreaks.com/topic/133029-alternate-row-color/#findComment-692022 Share on other sites More sharing options...
laffin Posted November 17, 2008 Share Posted November 17, 2008 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) Quote Link to comment https://forums.phpfreaks.com/topic/133029-alternate-row-color/#findComment-692077 Share on other sites More sharing options...
Peuplarchie Posted November 17, 2008 Author Share Posted November 17, 2008 THAT IT ! Finally ! Explode -- implode !!! Keys ! Thanks ! Quote Link to comment https://forums.phpfreaks.com/topic/133029-alternate-row-color/#findComment-692095 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.