What are the best practices for separating PHP and HTML code to maintain clean and readable code?

To maintain clean and readable code, it is best practice to separate PHP and HTML code by using a templating system or by utilizing PHP's alternative syntax for control structures. This separation helps improve code organization, readability, and maintainability.

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

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