Sarkar Hasan Sarkar Hasan - 6 months ago 10
PHP Question

Is it alright if I include multiple html files in a single php file?

I have a php file with multiple forms.. for simplicity's sake I have created multiple html file and each of them has a form and starts from

<html>
and ends with
</html>
.

the php file is something like this:

<?php
include('f1.html');
include('f2.html');
...
?>


The result of this seems okay.. my question is, it is okay if I keep it like this or I have to create head.html and end.html then includes forms in between??
what is the differences??

Any help is appreciated
Thanks

Answer

Yes, you can include as many as you want. But each html file should not contain <html /> enclosed. You should put it in your main file and the file which you want to include - in that file just use div wrapper to include your content. I mean you can use any html tag that you use the tag inside body tag.

But as per google page speed guide, you should maintain least html size as far as possible.

Here's an example:

main.php:

<!DOCTYPE html>
<html>
<head>
  <title>Example page</title>
</head>
<body>
  <?php 
    include('f1.html');
    include('f2.html');
  ?>
</body>
</html>

f1.html and f2.html:

<div>
your content
</div>
Comments