Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.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
什么';使用php includes包含外部内容的最佳方式是什么?(适用于热爱最佳实践的web开发人员)_Php_Jquery_Include - Fatal编程技术网

什么';使用php includes包含外部内容的最佳方式是什么?(适用于热爱最佳实践的web开发人员)

什么';使用php includes包含外部内容的最佳方式是什么?(适用于热爱最佳实践的web开发人员),php,jquery,include,Php,Jquery,Include,我已经检查了很多关于的教程,包括使用php“include”的页眉、导航和页脚。但是我最终分离了我的html标记。例如,my位于“header.html”中,而关闭的标记位于页脚中。当我使用jQuery时,这给了我一些问题,看起来有点混乱。是否有更好的做法来生成外部内容?(jQuery是解决方案吗?) index.php <?php include("header.html"); ?> <?php include("navigation.html"); ?> <di

我已经检查了很多关于的教程,包括使用php“include”的页眉、导航和页脚但是我最终分离了我的html标记。例如,
my
位于“header.html”中,而关闭的
标记位于页脚中。当我使用jQuery时,这给了我一些问题,看起来有点混乱。是否有更好的做法来生成外部内容?(jQuery是解决方案吗?)

index.php

<?php include("header.html"); ?>
<?php include("navigation.html"); ?>
<div id="content">
    <h2 class="clear">This is the contact page</h2>
        <p>
        Main content here... Main content here... Main content here... Main content here...
        Main content here... Main content here... Main content here... Main content here...
        Main content here... Main content here... Main content here... Main content here...
        Main content here... Main content here... Main content here... Main content here...
        Main content here... Main content here... Main content here... Main content here...
        Main content here... Main content here... Main content here... Main content here...
        </p>
    </div>
<?php include("footer.html"); ?>

这是联系页面

这里的主要内容。。。这里的主要内容。。。这里的主要内容。。。这里的主要内容。。。
这里的主要内容。。。这里的主要内容。。。这里的主要内容。。。这里的主要内容。。。
这里的主要内容。。。这里的主要内容。。。这里的主要内容。。。这里的主要内容。。。
这里的主要内容。。。这里的主要内容。。。这里的主要内容。。。这里的主要内容。。。
这里的主要内容。。。这里的主要内容。。。这里的主要内容。。。这里的主要内容。。。
这里的主要内容。。。这里的主要内容。。。这里的主要内容。。。这里的主要内容。。。

header.html

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>Study at Best</title>
    <script type="text/javascript" src="scripts/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="scripts/jquery.corner.js"></script>
    <script type="text/javascript" src="scripts/jquery.dropshadow.js"></script>
    <script type="text/javascript" src="scripts/jqueryScripts.js"></script>
    <link rel="stylesheet" rev="stylesheet" href="styles/layout.css" />
    <link rel="stylesheet" rev="stylesheet" href="styles/ddm.css" />
</head>
<body>
<div id="container">
    <div id="header">
    This is the header
    </div>
    <div id="footer">
        <p>BEST School &copy; Copyright 2009</p>
    </div>
</div>
</body>
</html>

学习充其量
这是标题
footer.html

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>Study at Best</title>
    <script type="text/javascript" src="scripts/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="scripts/jquery.corner.js"></script>
    <script type="text/javascript" src="scripts/jquery.dropshadow.js"></script>
    <script type="text/javascript" src="scripts/jqueryScripts.js"></script>
    <link rel="stylesheet" rev="stylesheet" href="styles/layout.css" />
    <link rel="stylesheet" rev="stylesheet" href="styles/ddm.css" />
</head>
<body>
<div id="container">
    <div id="header">
    This is the header
    </div>
    <div id="footer">
        <p>BEST School &copy; Copyright 2009</p>
    </div>
</div>
</body>
</html>

最佳学校&复制;版权所有2009


这会导致什么问题?这是一个相当标准的做法(我使用它),我从来没有知道它会产生任何问题。jQuery不应该是一个问题,因为在所有html连接在一起之前,不会运行jQuery代码。

不应该造成任何问题。
就个人而言,如果导航很简单,我会将其放在标题中,如果不是,我会通过PHP动态生成它并将其放在一个类中,然后将该类包含在标题中。

我认为这没有问题。我以前使用过很多次这种技术。对我来说,它使一切都井然有序。正如Jonathan Sampson所说,jQuery不应该有任何问题。

在我个人看来,这看起来不对。我的意思是不要这样对自己。如果网站变得更复杂,那将是一场噩梦。如果只将footer div放在footer.html中,与header.html相同,那又如何?其余部分属于index.php。如果index.php变得复杂,请将其进一步拆分(javascript.html.)merkuro Jun 20:21:22,好吧,我不确定这是否是更好的方法,但我倾向于使用一个模板文件,其中包含页眉、页脚、菜单、左侧、右侧,任何其他不特定于一个页面的内容,包括所有js包含的内容等等。
然后index.php就会有一个内容变量,其中包含所有索引内容。在索引的末尾,我需要一个模板文件,该文件将“content”变量放在它所属的位置,而tada,你所有的烦恼都结束了。

在我个人看来,这看起来不太正确。我的意思是不要这样对自己。如果网站变得更复杂,那将是一场噩梦。如果只将footer div放在footer.html中,与header.html相同,那又如何?其余部分属于index.php。如果index.php变得复杂,请将其进一步拆分(javascript.html..)。