What are the best practices for structuring PHP code within HTML for optimal output?

When structuring PHP code within HTML for optimal output, it is best practice to separate the PHP logic from the HTML markup to improve readability and maintainability. This can be achieved by using PHP opening and closing tags within the HTML code to insert dynamic content or execute PHP logic.

<!DOCTYPE html>
<html>
<head>
    <title>PHP within HTML</title>
</head>
<body>
    <h1>Welcome, <?php echo $username; ?></h1>
    
    <?php
    // PHP logic for dynamic content
    $currentDate = date("Y-m-d");
    echo "<p>Today's date is: $currentDate</p>";
    ?>
</body>
</html>