如何将 PHP 变量回显到样式表的 href 属性中测试网站

问题描述 投票:0回答:1

我有这三个文件:

index.php

<?php include('variables.php') ?>

<!DOCTYPE html>
<html lang="en">
<head>
    <title>TestWebsite</title>
    <link rel="stylesheet" href="<?php echo($folder . 'css/styles.css')?>">
</head>

变量.php

<?php
$folder = "C:/xampp/htdocs/Website/";

css/styles.css

/* Insert styling stuff here */

index.php和variables.php存储在根目录下。由于某种原因,样式表拒绝链接,我需要帮助找出原因。不过这工作得很好:

    <link rel="stylesheet" href="styles.css">

  • 尝试将
    <?php echo($folder . 'css/styles.css')?>
    放入单独的 php 文件中,看看我是否正确附加了目录。
  • 尝试将 styles.css 从其父文件夹移动到主目录中
  • 试过
        <link rel="stylesheet" href="<?php echo $folder ?>css/styles.css">
  • 在index.php中有使用$folder的include()并且工作得很好。
  • 我开始怀疑这是否是范围问题
php html css directory href
1个回答
0
投票

您没有为本地文件路径指定协议。在这种情况下,它是协议路径

file://

© www.soinside.com 2019 - 2024. All rights reserved.