Jump to content

Recommended Posts

Hey guys,

 

I have some values pulled from a .txt file which are echo'ed out on a page. E.g

 

Value1, Value2, Value3, Value4

 

What i'd like to do is get some code to highlight each output in this order: red, yellow and blue. E.g

 

Red    | Yellow | Blue  | Red

Value1 | Value2 | Value3 | Value4

 

 

I have so far attempted this but need some help/ideas about what to try next? I have defined three variables for the red, yellow and blue html tags. But need to apply them in order still.

 

$lines = file("file.txt"); //open file
  foreach ($lines as $line) { 
$data[$key] = explode("|", $line);

	$catname = trim($data[$key][1]); //define data needed


$a = "<font style=\"background-color: red\" size=\"3\">"; //red html highlight
$b = "<font style=\"background-color: yellow\" size=\"3\">"; //yellow html highlight
$c = "<font style=\"background-color: blue\" size=\"3\">"; //blue html highlight

$array = array($a, $b, $c); //i think i need to use a array?

print '<strong>'.$catname.'</strong></font>'; // print values and html highlight

 

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/90658-colour-ordered-text/
Share on other sites

try

$col=0;
$lines = file("file.txt"); //open file
$a = "<font style=\"background-color: red\" size=\"3\">"; //red html highlight
$b = "<font style=\"background-color: yellow\" size=\"3\">"; //yellow html highlight
$c = "<font style=\"background-color: blue\" size=\"3\">"; //blue html highlight
$array = array($a, $b, $c); //i think i need to use a array?
foreach ($lines as $line) { 
$data[$key] = explode("|", $line);
$catname = trim($data[$key][1]); //define data needed
        print $array[$col++ % 3].'<strong>'.$catname.'</strong></font>'; // print values and html highlight

Link to comment
https://forums.phpfreaks.com/topic/90658-colour-ordered-text/#findComment-464784
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.