What potential pitfalls exist when working with PHP files and HTML code within the same document?

One potential pitfall when working with PHP files and HTML code within the same document is that it can lead to messy and hard-to-read code. To solve this issue, it is recommended to separate the PHP logic from the HTML markup by using PHP opening and closing tags to switch between PHP and HTML mode.

<?php
// PHP logic here

?>

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