What are some best practices for separating HTML and PHP code in PHP scripts?

Separating HTML and PHP code in PHP scripts helps improve code readability, maintainability, and reusability. One common practice is to use PHP to handle logic and data processing, while HTML is used for presentation. This can be achieved by using PHP to echo variables or function results within HTML markup, or by implementing a template system to separate the two.

<?php
// PHP logic
$variable = "Hello, World!";

// HTML presentation
?>
<!DOCTYPE html>
<html>
<head>
    <title>PHP/HTML Separation</title>
</head>
<body>
    <h1><?php echo $variable; ?></h1>
</body>
</html>