How can PHP be used to create a main layout page that can be applied to multiple subpages with different content?

To create a main layout page that can be applied to multiple subpages with different content, you can use PHP include or require functions to include the main layout file in each subpage. Within the main layout file, you can define placeholders for dynamic content that will be replaced by the specific content of each subpage. This allows you to maintain a consistent layout across multiple pages while easily updating the main layout in one central location.

// main_layout.php

<html>
<head>
    <title>My Website</title>
</head>
<body>
    <header>
        <h1>Welcome to My Website</h1>
    </header>
    
    <main>
        <?php echo $content; ?>
    </main>
    
    <footer>
        <p>© <?php echo date("Y"); ?> My Website</p>
    </footer>
</body>
</html>
```

```php
// subpage1.php

<?php
$content = "<h2>Subpage 1 Content</h2>
            <p>This is the content for Subpage 1.</p>";

require_once('main_layout.php');
?>
```

```php
// subpage2.php

<?php
$content = "<h2>Subpage 2 Content</h2>
            <p>This is the content for Subpage 2.</p>";

require_once('main_layout.php');
?>