CSS不想包含在文件中

时间:2019-07-28 19:38:43

标签: php html css xampp

我通过自动为站点创建CSS来设置xampp php网站(如果创建了名为xyz.php / html的站点,那么也会创建一个CSS)。不幸的是,css不想使用php echo和html标签包含在网站中。没错

在style.php中:

$arr = explode("/",$_SERVER['PHP_SELF']);
$style = "";
foreach ($arr as $key){
    if(strpos($key, ".php")){
        $style = str_replace(".php", "style.css", $key);
    }
}
if($fp = fopen($_SERVER['DOCUMENT_ROOT']."/TestPHP/".$addr,"wb+")){
    fwrite($fp,"body{background-color:#666;}");
    fclose($fp);
}
echo $addr = "lib/require/styles/".$style;
echo '<link href="'.$addr.'" rel="stylesheet">';

在index.php中:

require_once 'lib/require/php/styles.php';

1 个答案:

答案 0 :(得分:0)

那是因为唯一的HTML(如我在代码中看到的)除了样式,没有头,没有正文之外没有别的什么……为什么不直接将HTML粘贴到文件中而不是PHP回声了吗?