What are common pitfalls when using PHP to generate HTML output?

One common pitfall when using PHP to generate HTML output is mixing PHP logic with HTML markup, making the code difficult to read and maintain. To solve this, it's recommended to separate PHP logic from HTML markup by using a template engine like Twig or by using PHP's alternative syntax for control structures.

<?php
// Example using PHP's alternative syntax for control structures
$items = ['Apple', 'Banana', 'Orange'];

?>
<ul>
<?php foreach ($items as $item): ?>
    <li><?php echo $item; ?></li>
<?php endforeach; ?>
</ul>