Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.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
链接嵌套在pages文件夹中的php文档中的CSS文件_Php_Html_Css_File Structure - Fatal编程技术网

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

链接嵌套在pages文件夹中的php文档中的CSS文件,php,html,css,file-structure,Php,Html,Css,File Structure,这里是网络开发新手。我的网站越来越大,最近采取了一些措施来帮助管理它,包括: 使用单独的header.php;footer.php;以及带有includes标记的navigation.php文件 在根目录/页下归档其他页。下面是我当前文件夹的快照: 根 页数 资产 图像 js php 我的问题是,我在pages文件夹中嵌套了其他页面(index.html除外)。在对这些文件进行编码时,由于相对/绝对文件引用,链接/包含文件会导致问题。通过一些研究,我能够使用这段php代码,它似乎适用于

这里是网络开发新手。我的网站越来越大,最近采取了一些措施来帮助管理它,包括:

  • 使用单独的header.php;footer.php;以及带有includes标记的navigation.php文件
  • 在根目录/页下归档其他页。下面是我当前文件夹的快照:
      • 页数
      • 资产
      • 图像
      • js
      • php
    我的问题是,我在pages文件夹中嵌套了其他页面(index.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, array(
    $_SERVER['DOCUMENT_ROOT'],
    get_include_path()
    ) ) );
    
    include 'root/css/style-services.css';
    
    ?>
    
    
    

    在使用文件结构和php包含函数时,如何确保引用的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
    //
    ?>
    

    不要包含CSS文件,只要
    echo
    它就可以了。比如:

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