What are some best practices for structuring PHP files when including external content in a webpage?

When including external content in a webpage using PHP, it is good practice to separate your PHP logic from your HTML markup for better organization and maintainability. One common approach is to use PHP include statements to separate reusable code into separate files and then include them where needed in your main PHP file.

// header.php
<!DOCTYPE html>
<html>
<head>
    <title>My Website</title>
</head>
<body>

// index.php
<?php include 'header.php'; ?>
<h1>Welcome to my website!</h1>
<p>This is some content on the homepage.</p>

// footer.php
</body>
</html>

// index.php
<?php include 'header.php'; ?>
<h1>Welcome to my website!</h1>
<p>This is some content on the homepage.</p>
<?php include 'footer.php'; ?>