Hello, can I pass on something?

<?php $color='red' ?> <link rel="stylesheet" href="link_css.css" > link_css.css p{color:<? echo $color ?>} 
  • Do not engage in this nonsense! Transfer to css file variable. For a long time, many people use something handy, something that is more suitable for changing the color for a paragraph. @Jim_Moriarty his answer, I think, is quite correct. But the question asked is not a solution at all. It is better not to do this (based on the question!) - Artem
  • +1 it’s better not to do that at all - Gedweb

5 answers 5

1 option. Use instead of the css-file php-file. Add a header to the top of the php file:

 <?php header("Content-type: text/css"); ?> 

It is connected as a normal css-file, not including:

 <link rel="stylesheet" href="style.php" /> 

But. Does not work in IE.

Option 2. Process css-files as php. Add the following lines to your .htaccess file:

 <Files style.css> ForceType application/x-httpd-php AddHandler application/x-httpd-php .css </Files> 

The stype.css file will be processed as a PHP file . It is connected as usual:

 <link rel="stylesheet" href="style.css" /> 
  • Thanks you. - zloctb
  • in any of the above examples I advise you to take care of caching, at least from the client side - Gedweb

Most likely, you need this <p style="color:<?echo $color?>">Text...</p>

  • I know about this method. Thank you for your attention to the question. - zloctb

It would be more correct to use different classes, the names of which are substituted into the template using php

 <p class="<?php echo $class;?>">Text...</p> 

or with a certain logic:

 <p class="<?php echo (условие) ? $class1 : $class2;?>">Text...</p> 

    Talk a topic started by @khvorostin . We connect the style with the color parameter

     <link rel="stylesheet" href="link_css.css?color=red" > 

    and in link_css.css

     p{color:<?=$_GET['color'];?>} 

      If there are not many such dynamic styles, you can add them directly to HTML through the style tag in the head section. Then it will not be necessary to process css files as php.