Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.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 - Fatal编程技术网

Php 更新头文件中包含的CSS文件

Php 更新头文件中包含的CSS文件,php,css,Php,Css,style.css包含在header.inc.php中 app dir css style.css inc header.inc.php footer.inc.php index.php login.php register.php 在创建新页面(login.php)时,目标是将样式添加到标题中的include(d)CSS中。不仅仅是将

style.css包含在header.inc.php中

app dir



          css

              style.css

          inc

              header.inc.php

              footer.inc.php

  index.php

  login.php

  register.php

在创建新页面(login.php)时,目标是将样式添加到标题中的include(d)CSS中。不仅仅是将css放置在标记中的任何位置,以下是我的尝试,它已经失败:

<?php

//Include a error reporting:

include '../../errorReport.inc.php';

// Set default timezone:

define('TZ', date_default_timezone_set('America/Los_Angeles') );

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>

    <title>

    <?php

    if(defined('TITLE'))

    {

        print TITLE;

    } else {

        print 'Raise High the Roof Beam! A J.D. Salinger Fan Club';

    }



    ?>

    </title>

    <meta http-equiv="content-type" content="text/html; charset=utf-8" />

    <link rel="stylesheet" href="./c/screen.css" media="screen,projection" />

</head>

错误消息

这将打印到UA:

<?php

header('content-type:text/css', replace);

header("Expires: ".gmdate("D, d M Y H:i:s", (time()+900)) . " GMT");

$errorColor = '#900';

echo '.error{ color: '.$errorColor.'; }';

?>

<?php include 'inc/header.inc.php';?>

<p class=\"error\">Error MSG</p>

<?php include 'inc/footer.inc.php';?>
.error{color:#900;}
把顶梁抬高!J.D.塞林格粉丝俱乐部
.................................
。错误{color:#900;}
需要位于
内的
标记内,而不是位于文档的最顶部

.error{ color: #900; }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title>
    Raise High the Roof Beam! A J.D. Salinger Fan Club  </title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="./c/screen.css" media="screen,projection" />
</head>
<body>
<div id="wrapper">
.................................

简单的答案是,您应该在样式表style.CSS中包含这个CSS,因为它是常量

如果您希望这是动态的,您需要稍微修改您的方案。这是一个框架将有帮助的地方,因为您所做的任何选择都会有点麻烦。也就是说,考虑这些选项:

A) 在login.php中,设置
$headerCss='.error{color:'.$errorColor..;}'
,然后在header.inc.php中,在
标记的正前方添加:

if (is_array($css)) {
    echo '<style type="text/css">' . implode("\n", $css) . '</style>';
}

更新至以下inc/header.inc.php:

if ($pageName == 'login') {
    print '<style type="text/css">';
    print '    .error { color: #900; }';
    print '</style>';
}

J.D.塞林格粉丝俱乐部

最爱的语录

我不知道我说的是什么意思,但我是认真的。
-麦田里的守望者

我私下告诉你,老朋友。。。请接受我这束朴实无华的早花括号:(((())。
高举屋梁,木匠和西摩:介绍

CSS测试:

<?php 
//Include a error reporting:
include '../../errorReport.inc.php'; 
// Set default timezone:
define('TZ', date_default_timezone_set('America/Los_Angeles') );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title>
    <?php
    if(defined('TITLE'))
    {
        print TITLE;
    } else {
        print 'Raise High the Roof Beam! A J.D. Salinger Fan Club';
    }

    ?>
    </title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="./c/screen.css" media="screen,projection" />

    <?php
    if(is_array($css)) {
    echo '<style type="text/css">';

    foreach ($css as $constant)
    {
        //print"<p />$prop";
            foreach($constant as $vars){

            echo  $vars;

            }
    }
    echo '</style>';
}   
    ?>
</head>
<body>
<div id="wrapper">

    <div id="header">
        <p class="description">A J.D. Salinger Fan Club</p>
        <h1><a href="index.php">Raise High the Roof Beam!</a></h1>
        <ul id="nav">
            <li><a href="books.php">Books</a></li>
            <li><a href="#">Stories</a></li>
            <li><a href="#">Quotes</a></li>
            <li><a href="login.php">Login</a></li>
            <li><a href="register.php">Register</a></li>
        </ul>
    </div><!-- header -->

    <div id="sidebar">
        <h2>Favorite Quotes</h2>
            <p class="news">I don't exactly know what I mean by that, but I mean it.<br />- <em>The Catcher in the Rye</em></p>
            <p class="news">I privately say to you, old friend... please accept from me this unpretentious bouquet of early-blooming parentheses: (((()))).<br />- <em>Raise High the Roof Beam, Carpenters and Seymour: An Introduction</em></p>
    </div><!-- sidebar -->

    <div id="content">
        <!-- BEGIN CHANGEABLE CONTENT. -->

错误消息


如果输出的是文本/css mime类型,那么整个文档应该是css。添加一些HTML只会导致无效/损坏的css。谢谢,我从目标文件中删除了header(),css数组()可以按需要工作。此外,还将研究如何使用PHP打开和重写css文件。非常感谢。
if ($pageName == 'login') {
    print '<style type="text/css">';
    print '    .error { color: #900; }';
    print '</style>';
}
<?php 
//Include a error reporting:
include '../../errorReport.inc.php'; 
// Set default timezone:
define('TZ', date_default_timezone_set('America/Los_Angeles') );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title>
    <?php
    if(defined('TITLE'))
    {
        print TITLE;
    } else {
        print 'Raise High the Roof Beam! A J.D. Salinger Fan Club';
    }

    ?>
    </title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="./c/screen.css" media="screen,projection" />

    <?php
    if(is_array($css)) {
    echo '<style type="text/css">';

    foreach ($css as $constant)
    {
        //print"<p />$prop";
            foreach($constant as $vars){

            echo  $vars;

            }
    }
    echo '</style>';
}   
    ?>
</head>
<body>
<div id="wrapper">

    <div id="header">
        <p class="description">A J.D. Salinger Fan Club</p>
        <h1><a href="index.php">Raise High the Roof Beam!</a></h1>
        <ul id="nav">
            <li><a href="books.php">Books</a></li>
            <li><a href="#">Stories</a></li>
            <li><a href="#">Quotes</a></li>
            <li><a href="login.php">Login</a></li>
            <li><a href="register.php">Register</a></li>
        </ul>
    </div><!-- header -->

    <div id="sidebar">
        <h2>Favorite Quotes</h2>
            <p class="news">I don't exactly know what I mean by that, but I mean it.<br />- <em>The Catcher in the Rye</em></p>
            <p class="news">I privately say to you, old friend... please accept from me this unpretentious bouquet of early-blooming parentheses: (((()))).<br />- <em>Raise High the Roof Beam, Carpenters and Seymour: An Introduction</em></p>
    </div><!-- sidebar -->

    <div id="content">
        <!-- BEGIN CHANGEABLE CONTENT. -->
<?php
$errorColor = "#900";
$fontSize = "5em";


$cssColors = array('.error{ color: '.$errorColor.';}');
$cssfontSize = array('#mainHead{font-size: ' . $fontSize.';}');
$css = array('colors' => $cssColors, 'fontSize' => $cssfontSize);

?>

<?php include 'inc/header.inc.php';?>
<p class="error">Error MSG</p>
<?php include 'inc/footer.inc.php';?>