Antonio Vallez Antonio Vallez - 1 year ago 64
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download