sh0wtym3 Posted April 7, 2010 Share Posted April 7, 2010 Hey, I have two blocks of CSS, shown here .myClass#myFirstID h3{ display:block; width:120px; background-image:url(images/myimage.png); background-repeat:no-repeat; background-position:top center; padding-top:15px; background-color:#999; font-size:12px; text-align:center; color:#FFF; } .myClass#mySecondID h3{ display:block; width:120px; background-image:url(images/sideAdH3_blank-top.png); background-repeat:no-repeat; background-position:top center; padding-top:15px; background-color:#EEE; font-size:12px; text-align:center; color:#FFF; } I'm looking for a way to update the second block "#mySecondID" and replace the value it has for bgcolor (EEE) with the value that the first block has (999) Is there a way to do this with PHP? RegEx maybe? Or should I be looking around the Javascript department Link to comment https://forums.phpfreaks.com/topic/197876-updating-css-using-php-is-it-possible/ Share on other sites More sharing options...
Jax2 Posted April 7, 2010 Share Posted April 7, 2010 Believe it or not, you can call a .css file that ends in .php the same as one that ends with .css I have it on my site currently so the admin can change colors of different things on the fly and it works perfectly. Just rename your .css file to something like styles.php and call it in your header like usual (with .php at the end)... Then for the colors, you can simply echo a variable that is stored in a database. So, at the very top of your php css file, do a simple SQL query to the table you're going to store and put all the CSS code into a while loop. styles.php: <?php include ("../includes/db.php"); $sql="select * from configure"; $result=mysql_query($sql, $db); while ($row=mysql_fetch_array($result)) { ?> body { font: 100% Verdana, Arial, Helvetica, sans-serif; background: #<?php echo $row['background_color'];?>; background-image:url('../images/<?php echo $row['background_image'];?>'); margin: 0; padding: 0; text-align: center; color: #<?php echo $row['Text_color'];?>; } blabla { } and so on ... <?php } ?> Link to comment https://forums.phpfreaks.com/topic/197876-updating-css-using-php-is-it-possible/#findComment-1038460 Share on other sites More sharing options...
sh0wtym3 Posted April 7, 2010 Author Share Posted April 7, 2010 Sweet, thanks for the help, PHP rules Link to comment https://forums.phpfreaks.com/topic/197876-updating-css-using-php-is-it-possible/#findComment-1038466 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.