开发者

load HTML\PHP pages into another Page's div

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...开发者_运维百科.

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

<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


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

(change links.html to 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.

eg:

include("subfolder/links.html");


Use the require function to add the content of the other files to your template.

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

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


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

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


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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜