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

Moo*_*oon 2 html css php

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

现在我要创建一个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>
Run Code Online (Sandbox Code Playgroud)

怎么做

Chr*_*phe 11

你可以使用include函数(require(),require_once()函数也可以),如下所示:

(将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>
Run Code Online (Sandbox Code Playgroud)

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

例如:

include("subfolder/links.html");
Run Code Online (Sandbox Code Playgroud)