如何在CSS中运行PHP [英] How do i run PHP inside CSS
问题描述
我有一个样式表链接,如此
i have a stylesheet link like so
<link href="css/<? echo $theme;?>/styles.css" rel="stylesheet" type="text/css" />
在CSS中我想能够回显由db
Inside the CSS I want to be able to echo a background image outputted by the db
body{ background-image:url(../../images/<?php echo $theme.'/'.$background;?>);}
我尝试在页面的开头添加以下内容,以HTML代码输出所有内容
I tried adding the following to the beginning of my page but it just output everything in html code
<? header ("Content-type: text/css");?>
确定有一点,任何人都可以提出最好的行动方案?
Im sure there is a bit to this, can anyone advise the best course of action?
提前感谢
推荐答案
将文件结尾更改为php,通过服务器,一旦你做了,你可以链接到它,如果它是一个常规的css文件,并确保头正确设置与该头文件代码,你在文件的顶部
Change the file ending to php so it gets run by the server, and once you've done that you can link to it as if it was a regular css file and make sure the header is correct set with that header code you have at the top of the file
更改:
<link href="css/<? echo $theme;?>/styles.css" rel="stylesheet" type="text/css" />
收件人:
<link href="css/<? echo $theme;?>/styles.php" rel="stylesheet" type="text/css" />
和该文件的顶部
<? header ("Content-type: text/css");?>
由于您似乎已启用 php shorttags 使用而不是使用
And btw since you seem to have php shorttags already enabled you might aswell use instead of using
<? echo $var;?>
使用
<?=$var;?>
这篇关于如何在CSS中运行PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!