What are some common pitfalls to avoid when combining HTML and PHP code within the same file?

One common pitfall to avoid when combining HTML and PHP code within the same file is mixing them haphazardly, which can lead to messy and hard-to-maintain code. To solve this, it's recommended to separate the PHP logic from the HTML markup by using PHP opening and closing tags within the HTML code.

<?php
// PHP logic here
?>

<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
</head>
<body>
    <h1><?php echo "Hello, World!"; ?></h1>
</body>
</html>