链接嵌套在页面文件夹中的php文档中的CSS文件

问题描述

此处是Web开发新手。我的网站越来越大,最近已采取一些措施来管理它,包括

  1. 使用单独的header.PHP; footer.PHP;和带有includes标签的navigation.PHP文件
  2. 将其他页面归档在根目录/页面下。下面是我当前文件夹的快照:

我的问题是,我在页面文件夹中嵌套了其他页面(除ind​​ex.html之外)。对这些文件进行编码时,由于相对/绝对文件引用,链接/包含文件引起了问题。通过一些研究,我能够使用此PHP代码,该代码似乎适用于页眉,页脚和导航菜单

<?PHP 
set_include_path( implode( PATH_SEParaTOR,array(
$_SERVER['DOCUMENT_ROOT'],get_include_path()
) ) );

include 'root/assets/header.PHP';

?>

我现在遇到的问题是css链接也不再起作用:

 <link rel="stylesheet" href="css/style-services.css">

我尝试这样做没有运气:

<?PHP 
set_include_path( implode( PATH_SEParaTOR,get_include_path()
) ) );

include 'root/css/style-services.css';

?>

当使用文件结构和PHP include函数时,如何确保引用的CSS也被包含?

解决方法

不包含CSS文件,只需echo即可。喜欢:

<?php
//
// your other cods here
//
$style_services = file_get_contents ("root/css/style-services.css");
echo $style_services;
//
// your other cods here
//
?>