Why split the html into sections within PHP?

Ive seen some online examples when dealing with databases and larger projects. Alot of the projects ive seen separate the HTML into sections giving it its own php file.
EX:
Header.php
Maincontent.php
footer.php
etc.

Why do that? What is the benefit of splitting a single html php file into multiple php files for each section of the html?

Here is an example i saw it in: PHP HTML split

ANy insight or hint is appreciated!

Try this.

Create 30 very simple pages that do not have “sections”, ensuring each page looks similar.

Now make a change to the header section.

Then make a change to the footer.

Then make another change to the header.

Now create another 10 pages that also look like the others.

When you get done doing that, please report back on the experience.

5 Likes

It makes it very modular, and very reusable. It’s a very common pattern for assembling new things, and not only in PHP.

You can do it with just two files - one for the unique page content and one for all the common stuff. Instead of having separate header and footer files you’d have separate header and footer functions in the common file and call them from the appropriate spot in each unique page. Alternatively you invert it and have all pages generated from the common file that contains all of the layout and an include that uses a parameter passed to it to determine which unique content to display.

1 Like

Haha why create so many pages lol! Well if im reading it write, wouldnt all the headers and footer change and look the same across all pages because of that 1 edited file?

That makes sense, im assuming this style of programming is best when including a project that is over 5 pages long snd requires the footer and header to be nearly/exactly the same. Is there any other programming tip like the one mentioned on this thread for php? Since im herr i might as well pick up skills from thoses experienced!

Thank you for your time!

Modern software architecture patterns such as those listed below.

  • OOP (object-oriented programming)
  • MVC (separation of concerns)
  • ORM (object-relational mapping)_
  • Dependency management
  • Dependency injection via IoC (inversion of control container)
  • Version control

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.