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.
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>";
}
}
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>';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With