0

so want to auto create a whole html page i was thinking like this

$newhtml = '<html><head></head><body>'.$variable.'</body></html>';
file_put_contents ('file.html',$newhtml);

this would be the proper thing to do?

Edited by centenond

3
Contributors
3
Replies
20
Views
3 Years
Discussion Span
Last Post by centenond
1

Not really... I would separate it into a head, body and footer.

Then in my php I would include the header using include('head.php')
Another common practice is to create entire page templates.

1

As iawmthwee states, you will probably have common features for all pages, such as footers, headers (banners, nav areas) and maybe side panels.

There are a number of ways to do this. You could do this for each 'page':

$page = basename($_SERVER['PHP_SELF']);
if(file_exists("pages/$page"))
{
    require "includes/header.php";
    require "pages/$page";
    require "includes/footer.php";
}else{
    //provide a default page or set a 404
}

Just an example. That way you don't have to duplicate header, footer etc...

Edited by diafol

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.