Page 1 of 1

Importing an html file

Posted: Sat Nov 01, 2003 6:46 pm
by jayr517
Hey all. Does anyone know of a way to import an html file into html that's already written?

For example, I have this code:

Code: Select all

<HTML>
<HEAD>
<TITLE>Under Construction</TITLE>
<LINK rel="stylesheet" type="text/css" href="./css/default.css"/>
<?php
$headerStyle     = "";
$trailerStyle    = "";
$navbarStyle     = "";
$banner          = "";
$bannerLink      = "";
require_once("./php/HeaderClasses.php");
require_once("./php/TrailerClasses.php");
require_once("./php/NavigationClasses.php");
$header  = new Header($headerStyle, $banner, $bannerLink);
$trailer = new Trailer($trailerStyle);
$navbar  = new NavBar($navbarStyle);
?>
<SCRIPT src="./js/common.js"></SCRIPT>
</HEAD>

<BODY>
<TABLE class="mainpage">
    <?php
        // header...
        $header->display();
    ?>
    <TR>
        <?php
            // Nav Bar...
            $navbar->display();
        ?>
        <TD class="mainpage">
            <?php
                // Body...
                THIS IS WHERE I WANT TO IMPORT THE HTML FILE.
            ?>
        </TD>
    </TR>
    <?php
        // trailer...
        $trailer->display();
    ?>
</TABLE>
</BODY>
</HTML>
Note...the html file I want to import is a full file (which includes the open and close html, title, head, and body tags).

Anyone, anyone...beuller, beuller???

Posted: Sat Nov 01, 2003 7:12 pm
by Gen-ik
I have no idea why you would want to do that. And don't forget that importing someone else's webpage into your webpage could be in breach of copyright (if you are doing that).

Why don't you just use an <iframe> ?

Posted: Sat Nov 01, 2003 7:25 pm
by jayr517
Well thank you for the law review, but I'm aware of that...;-)

I don't want scroll bars in the middle of my page, so IFRAMES don't work.

Posted: Sat Nov 01, 2003 7:31 pm
by Gen-ik
jayr517 wrote:Well thank you for the law review, but I'm aware of that...;-)

I don't want scroll bars in the middle of my page, so IFRAMES don't work.
Ok fine. So where shall we start from, importing the file into PHP or getting everything between the <body></body> tags once it's loaded?

Posted: Sat Nov 01, 2003 7:37 pm
by jayr517
ty...I really just want to get everything between the body tags. I actually tried just including the html file (include("./file.htm")) and it seemed to work ok, although my css attributes didn't apply. I'd rather not do that though, because it certainly is "standard" and I don't want to open myself up for weird things starting to happen with the site.

Is parsing the file the only way?

Posted: Sat Nov 01, 2003 7:48 pm
by Gen-ik
I'll give you the basics.....

Code: Select all

<?php

$file = "somepage.htm";

// Load the file into a variable.
$o = open($file, "rb");
$c = fread($o, filesize($file));
fclose($o);

// Get stuff between the body tags.
$sA = explode("<body>", $c);
$sB = explode("</body>", $sA[1]);
$contents = $sB[0];

// Echo the contents.
echo $contents;

?>
You might also want to check out.......

http://se.php.net/manual/en/function.fopen.php
http://se.php.net/manual/en/function.fread.php
http://se.php.net/manual/en/function.fclose.php
http://se.php.net/manual/en/function.explode.php

........for reference.

Posted: Sat Nov 01, 2003 8:12 pm
by jayr517
That's great, thanks a lot for the help.