【发布时间】:2014-09-23 23:59:03
【问题描述】:
我目前正在使用 PHP 变量从我的数据库中获取 CSS 值。这可以作为 php 包含,但是我想使用从数据库中提取的这些变量的输出生成一个静态 .css 文件。不知道该怎么做?
css.php
<?
$sql = $dbh->prepare("SELECT * FROM styles"); //gets background_color (#000) from DB
$sql->execute();
$result = $sql->fetch();
foreach ($result as $k => $v) {
$$k = $v; //makes background_color = $background_color = #000
}
<style type="text/css">
.content {
background-color: <?=$background_color?>;
}
?>
index.php
<? require_once "css.php"; ?>
我希望使用 css.php 生成的静态 styles.css 看起来像这样:
.content { 背景颜色: ; }
【问题讨论】:
-
我不久前处于完全相同的情况,可以找到解决方案 HERE ,如果 question 本身可以被投票,那就太好了,这样它可以作为参考