How can HTML files be modularized in PHP to avoid clutter and conditional statements?

When working with HTML files in PHP, one way to modularize them and avoid clutter and conditional statements is by using PHP's include or require functions to separate the HTML code into reusable components. By breaking down the HTML code into smaller, modular pieces, it becomes easier to manage and maintain. This approach also allows for better organization and reusability of code.

<?php
// header.php
include 'header.php';
?>

<!-- main content -->
<p>This is the main content of the page.</p>

<?php
// footer.php
include 'footer.php';
?>