Are there best practices or coding conventions to follow when combining PHP and HTML to avoid unexpected formatting issues like empty spaces at the top of a webpage?

When combining PHP and HTML, it's important to be mindful of whitespace and line breaks in your code, as they can result in unexpected formatting issues such as empty spaces at the top of a webpage. To avoid this problem, make sure to properly structure your PHP code within the HTML template by minimizing unnecessary whitespace and line breaks.

<?php
    ob_start(); // Start output buffering
?>
<!DOCTYPE html>
<html>
<head>
    <title>Example Page</title>
</head>
<body>
    <h1>Welcome!</h1>
    <p>This is an example page.</p>
</body>
</html>
<?php
    ob_end_flush(); // Flush output buffer
?>