Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
包括:扩展名为.php的CSS?_Php_Css_Include - Fatal编程技术网

包括:扩展名为.php的CSS?

包括:扩展名为.php的CSS?,php,css,include,Php,Css,Include,我想用PHP包装一个CSS文件。。。所以我为CSS文件编写头文件,并给它一个.php文件扩展名,因此。。。css.php 如果该页面已被用作包含,那么该操作是否有效?或者,此新标题是否会与页面所包含的框架冲突?如果includer脚本不发送任何输出,则它将正常工作,否则将出现“标题已发送”错误 在includer中使用ob_start()可以避免这种情况并使一切正常 Html框架与php包含无关,因此在本例中根本没有冲突。如果您有一个名为css.php的文件,请确保第一行设置了正确的内容类型标题

我想用PHP包装一个CSS文件。。。所以我为CSS文件编写头文件,并给它一个.php文件扩展名,因此。。。css.php


如果该页面已被用作包含,那么该操作是否有效?或者,此新标题是否会与页面所包含的框架冲突?

如果includer脚本不发送任何输出,则它将正常工作,否则将出现“标题已发送”错误

在includer中使用ob_start()可以避免这种情况并使一切正常


Html框架与php包含无关,因此在本例中根本没有冲突。

如果您有一个名为
css.php的文件,请确保第一行设置了正确的内容类型标题。您可能还想将会话设置内容(如果有的话)拆分为
bootstrap.php
,如果您还没有这样做的话。从数据库加载某些样式信息的快速示例:

<?php 
  header("Content-Type: text/css"); 
  include('bootstrap.php');
  // fetch some information to print out our styles
  $result = mysql_query("SELECT * FROM site_styles");
  while ($row = mysql_fetch_assoc($result)) {
    echo $row["selector"]." {\n".$row["css"]."\n}\n";
  }
?>
尽管大多数浏览器都会非常积极地缓存css文件,但您可能会发现动态更改该文件的内容并没有多大好处。您可以通过向链接的href添加get参数来强制更新,如下所示:

<link rel="stylesheet" type="text/css" href="css.php?<?php echo $cssversion ?>"/>
gnarf把它钉死了

我有:


HTML文件:

css.php文件:

如果CSS.php文件中的第一行代码不是
头(“内容类型:text/CSS;charset=utf-8”)它将不起作用

#-------------------#
#-------------------#
# FlyKit Mod v1.0   # By Ernest Buffington
#-------------------#
    
# put this in your MAIN file
function addPHPCSSToHead($content, $type='file'){
            global $headPHPCSS;
            if (($type == 'file') && (is_array($headPHPCSS) && count($headPHPCSS) > 0) && (in_array(array($type, $content), $headPHPCSS))) 
            return;
            $headPHPCSS[] = array($type, $content);
            return;
        }

# This is loaded in/from your header

    function load_this_from_your_header() 
    {
        global $headPHPCSS;
        
        if (is_array($headPHPCSS) && count($headPHPCSS) > 0) 
        {
            foreach($headPHPCSS AS $php) 
            {
                if ($php[0]=='file') 
                {
                    echo "<style type=\"text/css\">\n";
                    include($php[1]);
                    echo "</style>\n";
                } 
                else 
                {
                    echo "<style type=\"text/css\">\n";
                    include($php[1]);
                    echo "</style>\n"; 
                }
            }
        }
        return;
    }

# Use this to load the PHP CSS in your theme for fly editing.

    addPHPCSSToHead(some_dir.'somefile.php','file'); 

This allows you to edit CSS on the fly and the browser will not cache the changes. 
This is great for designing Themes etc.    
#FlyKit Mod v1.0#由欧内斯特·布芬顿制作 #-------------------# #把这个放在你的主文件里 函数addPHPCSSToHead($content,$type='file')){ 全球$headPHPCSS; 如果($type='file')&&(is_数组($headPHPCSS)&&count($headPHPCSS)>0)&(in_数组(数组($type,$content),$headPHPCSS))) 返回; $headPHPCSS[]=数组($type,$content); 返回; } #这是从标题中加载的 函数从\u您的\u头()加载此\u { 全球$headPHPCSS; if(is_数组($headPHPCSS)和计数($headPHPCSS)>0) { foreach($headPHPCSS作为$php) { 如果($php[0]=='file') { 回音“\n”; 包括($php[1]); 回音“\n”; } 其他的 { 回音“\n”; 包括($php[1]); 回音“\n”; } } } 返回; } #使用此选项在主题中加载PHP CSS以进行动态编辑。 addPHPCSSToHead(some_dir'somefile.php','file'); 这允许您动态编辑CSS,浏览器不会缓存更改。 这是伟大的设计主题等。
请问您想用这个
css.php
文件提供什么服务?一些由数据库生成的样式或什么的?你能展示一些代码吗?我有点搞不懂情况是什么。你也可以使用
标题(“内容类型:text/css;字符集:UTF-8”)确保页眉打印在文件的最顶端。如果你(像我一样)在顶部有一个空行,它可能在某个地方不起作用!看到你的答案被撕碎真是糟糕。
<link rel="stylesheet" type="text/css" media="screen" href="<? echo TMPL ?>css/name-of-file.css.php">
<?
header('Content-Type: text/css');
// print out your php-driven css...
?>
#-------------------#
# FlyKit Mod v1.0   # By Ernest Buffington
#-------------------#
    
# put this in your MAIN file
function addPHPCSSToHead($content, $type='file'){
            global $headPHPCSS;
            if (($type == 'file') && (is_array($headPHPCSS) && count($headPHPCSS) > 0) && (in_array(array($type, $content), $headPHPCSS))) 
            return;
            $headPHPCSS[] = array($type, $content);
            return;
        }

# This is loaded in/from your header

    function load_this_from_your_header() 
    {
        global $headPHPCSS;
        
        if (is_array($headPHPCSS) && count($headPHPCSS) > 0) 
        {
            foreach($headPHPCSS AS $php) 
            {
                if ($php[0]=='file') 
                {
                    echo "<style type=\"text/css\">\n";
                    include($php[1]);
                    echo "</style>\n";
                } 
                else 
                {
                    echo "<style type=\"text/css\">\n";
                    include($php[1]);
                    echo "</style>\n"; 
                }
            }
        }
        return;
    }

# Use this to load the PHP CSS in your theme for fly editing.

    addPHPCSSToHead(some_dir.'somefile.php','file'); 

This allows you to edit CSS on the fly and the browser will not cache the changes. 
This is great for designing Themes etc.