My stackoverflow answer #5

by krike in Other / Stackoverflow answers on 03 Nov 2010


Each week I feature one of my answers on stackoverflow hoping it might help other people.

The question

This weeks question by Junaid Saeed: load HTMLPHP 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 showload 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

My anwser

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.php"); //You cant include html files and therefore it should be a php file

Written by krike

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sit amet nisl nisl. Ut interdum libero vitae quam ultricies et lacinia elit aliquet. Praesent tincidunt, sem tempus feugiat feugiat, turpis tellus scelerisque erat, sit amet feugiat neque arcu ac lectus. Sed at mi et elit interdum scelerisque vitae eu felis.

krike has written 77 posts.