What are the best practices for separating PHP and HTML code to improve code readability and maintainability?

Separating PHP and HTML code is essential for improving code readability and maintainability. One common practice is to use PHP to handle logic and data processing, while HTML is used for the presentation layer. This separation also makes it easier to collaborate with front-end developers and designers, as they can focus on the HTML and CSS without needing to understand the PHP logic.

<?php
// PHP logic and data processing
$userName = "John Doe";
$userAge = 30;

// HTML presentation
?>
<!DOCTYPE html>
<html>
<head>
    <title>User Profile</title>
</head>
<body>
    <h1>Welcome, <?php echo $userName; ?>!</h1>
    <p>Your age is <?php echo $userAge; ?> years old.</p>
</body>
</html>