Herman Nz Herman Nz - 1 year ago 63
CSS Question

Change CSS value by using PHP

For example, I have this CSS script:


Then, I would like to change the header value to:


The values are stored in database. What makes me confused is which should be the best to do that: Using PHP script or CSS or even javascript.
I want it changed based on the CSS value from my database which I can change again when I need it (by using PHP script). Perhaps this question is too general but, please give me some scripts which I can perform it well.
Thanks for any help.

Answer Source

first, change the extension of your file from (e.g.) style.css to style.php . Then add this to the first line of your css:

<?php header('Content-Type: text/css'); ?>

and after that you can define the value of your background as a variable and change it easily.

background: <?php echo $value; ?>

and in your php file:

<?php value = "#fff"; ?>


<?php $value = "#fff"; ?>