php - 使用 PHP include 将文件包含在它自己的包含文件中

标签 php jquery html css

我正在尝试将 projects.php 文件加载到更高级别的 index.php 文件中,并希望维护所有 .js .css 和任何进一步嵌套(在 .js 文件中)的 .php 文件,这些文件在projects.php 文件。

我的 index.php 文件是这样的:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>BLST</title>
</head>

<body>
    <?php $projectsPage = "/tables/php/projects.php"?>
    <li><a href="index.php?page=<?php echo $projectsPage;?>">Projects</a></li>
    <?php if(is_null($_GET["page"])) { 
                $page = ""; 
        }else{ 
            $page = $_GET["page"]; 
        } 
       include($page); 
    ?>
</body>
</html>

我的projects.php文件是

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />

        <title>Projects</title>

        <style type="text/css">
            @import "css/test.css";
            @import "http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/themes/smoothness/jquery-ui.css";
        </style>

        <script type="text/javascript" language="javascript" charset="utf-8" src="js/jquery.min.js"></script>
    </head>

问题是找不到 projects.php 中的任何文件。这是因为浏览器现在正在查找我的主目录(index.php 所在的位置)。

最佳答案

test.css在“tables/php/css/test.css”中,projects.php和index.php的位置呢

我认为这些问题的答案将解决问题。

关于php - 使用 PHP include 将文件包含在它自己的包含文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22618759/

相关文章:

javascript - 使用 Javascript 用不同的元素替换 Angular div

JavaScript onclick() 文本大小随 EventListener 增加

jquery - 用户滚动时更新导航栏

javascript - 我可以创建一个设置为页面宽度的变量吗?

php - Symfony 表单事件向特定字段添加错误

php - 具有多个选项的 Twig json_encode

php - 如何通过 cURL 使用 stream_notification_callback

php - 通过 Android Studio 使用 MySQL 数据库登录应用程序

javascript - 根据值显示字段

javascript - 创建要加载的 JSON 的订单