How to format font style and color in an echo

I have a small piece of code that I want to create from an echo.

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

This does not work, and I was looking for some resources to try to implement this. Basically, I want font-family: Arial and font-size: 11px; and font color: # ff0000;

Any php help would be helpful.

+6
source share
6 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>"; } } 
+8
source
 echo "<span style = 'font-color: #ff0000'> Movie List for {$key} 2013 </span>"; 

Variables expand only in double quotation marks, not in single quotation marks. Since the above uses double quotes for a PHP string, I switched to single quotes for inline HTML to avoid having to avoid quotes.

Another problem with your code is that the <style> tags are for inputting CSS blocks, and not for styling individual elements. To create an element, you need an element tag with the style attribute; <span> is the simplest element - it has no native formatting, it just serves as a place to attach attributes.

Another popular way to write is string concatenation:

 echo '<span style = "font-color: #ff0000"> Movie List for ' . $key . ' 2013 </span>'; 
+3
source
  echo "<a href='#' style = \"font-color: #ff0000;\"> Movie List for {$key} 2013 </a>"; 
+2
source

Are you trying to reproduce a style or inline style? Inline style will look like

 echo "<p style=\"font-color: #ff0000;\">text here</p>"; 
+2
source
 echo '< span style = "font-color: #ff0000"> Movie List for {$key} 2013 </span>'; 
+1
source

You should also use the color style, not the font-color

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

In general, the comments on double and single quotes are true in other sentences. $ Variables are executed only in double quotes.

+1
source

Source: https://habr.com/ru/post/946428/


All Articles