What are the best practices for structuring PHP code within HTML elements to avoid conflicts with browser rendering?

When embedding PHP code within HTML elements, it is important to structure the code properly to avoid conflicts with browser rendering. One common practice is to separate PHP logic from HTML markup by using PHP opening and closing tags within the HTML code. This helps maintain readability and ensures that the PHP code is executed correctly without interfering with the rendering of the webpage.

<div>
    <?php
        $message = "Hello, World!";
        echo "<p>$message</p>";
    ?>
</div>