What are the potential pitfalls of directly outputting HTML within a PHP function, and what are alternative approaches to consider for cleaner code?

Directly outputting HTML within a PHP function can lead to mixing logic with presentation, making the code harder to maintain and debug. An alternative approach is to separate the HTML markup from the PHP logic using templates or a templating engine like Twig. This approach promotes cleaner code by keeping the presentation separate from the logic.

// Directly outputting HTML within a PHP function
function displayMessage($message) {
    echo "<div class='message'>$message</div>";
}
```

```php
// Separating HTML markup from PHP logic using a template
function displayMessage($message) {
    include 'templates/message.php';
}
```

In the `message.php` template file:
```html
<div class="message"><?php echo $message; ?></div>