将 HTML\PHP 页面加载到另一个页面的 div

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3573113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:16:09  来源:igfitidea点击:

load HTML\PHP pages into another Page's div

phpcsshtml

提问by Moon

lets say i have two pages links.html& contents.php... first page contains only html code while the second page contains some HTML + PHP code....

假设我有两页links.html& contents.php...第一页只包含 html 代码,而第二页包含一些HTML + PHP 代码....

now i ant to create a page index.phpwith two DIVs in which i want to show\load the above two pages...

现在我想要创建一个index.php包含两个 DIV的页面,我想在其中显示\加载上述两个页面...

<html>
<body>
    <div id="links" class="myCustom1">
    <!--here will be the links.html page-->
    </div>

    <div id="contents" class="myCustom2">
    <!--here will be the contents.php page-->
    </div>
</body>
<html>

HOW TO DO IT

怎么做

回答by Christophe

you can use the include functions (require(), require_once() functions would work as well), like this:

您可以使用包含函数(require()、require_once() 函数也可以),如下所示:

(change links.html to links.php)

(将 links.html 更改为 links.php)

<html>
<body>
    <div id="links" class="myCustom1">
    <?php include("links.php"); ?>
    </div>

    <div id="contents" class="myCustom2">
    <?php include("contents.php"); ?>
    </div>
</body>
<html>

I set it to links.html which is your filename but if it's in a subdirectory you need to specify it as well.

我将它设置为 links.html,这是您的文件名,但如果它位于子目录中,您也需要指定它。

eg:

例如:

include("subfolder/links.html");

回答by Maxim Manco

Use the requirefunction to add the content of the other files to your template.

使用require函数将其他文件的内容添加到您的模板中。

<html>
<body>
    <div id="links" class="myCustom1">
       <?php require('links.html'); ?>
    </div>

    <div id="contents" class="myCustom2">
        <?php require('content.php'); ?>
    </div>
</body>
<html>

回答by Adam Tomat

use the code people posted above, but make links.html a php file..

使用上面发布的代码,但将 links.html 设为 php 文件。

OR if you really dont want to do this you can tell the PHP engine to parse HTML pages.

或者,如果您真的不想这样做,您可以告诉 PHP 引擎解析 HTML 页面。

回答by Blue BOmb

Be sure to double check that the page you're loading (including or requiring) doesn't have the html head tags at the top of them.

请务必仔细检查您正在加载(包括或要求)的页面顶部是否没有 html head 标签。

I couldn't figure out why when I included a file, the page (which works without the include) wouldn't load. I viewed the source from my browser and found the html and head tags from the loaded page down at the point where I had included that file.

我不明白为什么当我包含一个文件时,页面(在没有包含的情况下工作)不会加载。我从浏览器中查看了源代码,并在我包含该文件的地方找到了加载页面中的 html 和 head 标记。