Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format font style and color in echo

I have a small snippet of code that I want to style from echo.

foreach($months as $key => $month){
  if(strpos($filename,$month)!==false){
        echo '<style = "font-color: #ff0000"> Movie List for {$key} 2013 </style>';
    }
}

This is not working, and I've been looking over some resources to try to implement this. Basically I want font-family: Arial and font-size: 11px; and the font-color: #ff0000;

Any php assistance would be helpful.

like image 579
ValleyDigital Avatar asked Jun 03 '13 17:06

ValleyDigital


2 Answers

foreach($months as $key => $month){
  if(strpos($filename,$month)!==false){
        echo "<div style ='font:11px/21px Arial,tahoma,sans-serif;color:#ff0000'> Movie List for $key 2013</div>";
    }
}
like image 197
Mahesh Avatar answered Oct 07 '22 07:10

Mahesh


echo "<span style = 'font-color: #ff0000'> Movie List for {$key} 2013 </span>";

Variables are only expanded inside double quotes, not single quotes. Since the above uses double quotes for the PHP string, I switched to single quotes for the embedded HTML, to avoid having to escape the quotes.

The other problem with your code is that <style> tags are for entering CSS blocks, not for styling individual elements. To style an element, you need an element tag with a style attribute; <span> is the simplest element -- it doesn't have any formatting of its own, it just serves as a place to attach attributes.

Another popular way to write it is with string concatenation:

echo '<span style = "font-color: #ff0000"> Movie List for ' . $key . ' 2013 </span>';
like image 32
Barmar Avatar answered Oct 07 '22 08:10

Barmar