How can PHP be used to display a specific page within a website layout?

To display a specific page within a website layout using PHP, you can use a combination of PHP includes and conditional statements. By creating a separate PHP file for each page content and then including it in the main layout file based on a parameter or variable, you can dynamically display different pages within the same layout structure.

<?php
$page = isset($_GET['page']) ? $_GET['page'] : 'home'; // Get the page parameter from the URL, default to 'home' if not set

if ($page == 'home') {
    include 'pages/home.php'; // Include the home page content
} elseif ($page == 'about') {
    include 'pages/about.php'; // Include the about page content
} elseif ($page == 'contact') {
    include 'pages/contact.php'; // Include the contact page content
} else {
    include 'pages/404.php'; // Include a 404 page if the specified page is not found
}
?>