How can PHP be used to separate design from functionality in a website?

To separate design from functionality in a website using PHP, you can utilize a templating system. This involves creating separate template files for the design elements (HTML, CSS) and using PHP to dynamically inject content into these templates. This allows for easier maintenance and updates to the design without affecting the underlying functionality of the website.

<?php
// Function to render a template file with dynamic content
function renderTemplate($template, $data) {
    ob_start();
    extract($data);
    include $template;
    return ob_get_clean();
}

// Example data to be injected into the template
$data = array(
    'title' => 'Welcome to our website',
    'content' => 'This is some sample content'
);

// Render the template file with the data
echo renderTemplate('template.php', $data);
?>