我有一个css文件heredoc作为php,其中定义了3个值
<?php header("Content-type: text/css");
$clabel = '#384DA0';
$cbackground = '#89A1BA';
$cfont = '#000000';
?>
我想根据mysql表中的值来更改这些变量。但如果不存在默认值,则保留默认值。
我该怎么做呢?
Thak
在使用heredoc:之前设置它们
$request = //do some database request here;
$clabel = $request['clabel'] ? $request['clabel'] : 'default value';
$myCSS = <<<EOT
.someclass{color: $clabel;}
EOT;
根据我对heredocs的(基本)了解,您的css应该使用正确分配的变量进行解析。