Antonio Vallez Antonio Vallez - 18 days ago 4x
PHP Question

Is it possible to each php in like css code?

I want to include a php script in a css file:

$str = "5px";
echo $str;

and then

.header {
font-size: $str;

Is it possible?


No, not like that. CSS isn't a programming language, and has NOTHING to do with PHP.

You can, however, have PHP generate the CSS:


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


header('Content-type: text/css');
$str = '5px';

.header {
    font-size: '<?php echo $str; ?>';

Note that since you'r GENERATING css, you have to make absolutely SURE that whatever PHP outputs will be valid for the context the output is going into. It is very easy to output something that'll be a CSS syntax error and kill the rest of the CSS file.