如何在PHP中包含CSS? [英] How can I include CSS in php?

查看:253
本文介绍了如何在PHP中包含CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过php包含我的css / stylesheet,以便...

i want to include my css/stylesheet via php so that...

<link rel="stylesheet" href="http://www.mydomain.com/css/style.php">

,以便我可以动态地更改不同的样式表....我如何做

so that i can than dynamicly change different stylesheets.... how can i do that

推荐答案

只要将 style.php 中的MIME类型设置为CSS,你应该在做生意。将此添加到最顶层:

As long as you set your MIME type in style.php to CSS, you should be in business. Add this to the very top:

<?php Header ("Content-type: text/css; charset=utf-8");?> 

如果你在Apache服务器上运行的另一个选项是告诉它检查.css文件PHP。将它添加到您的 .htaccess 文件中:

Another option if you're running on an Apache server is to tell it to check .css files for PHP. Add this to your .htaccess file to do this:

AddType application/x-httpd-php .css 

然后你可以简单地包含一个正常的.css文件:

Then you could simply include a regular .css file:

<link rel="stylesheet" href="http://www.mydomain.com/css/style.css">

这篇关于如何在PHP中包含CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆