What are some common pitfalls to avoid when using functions that output content in PHP?

One common pitfall to avoid when using functions that output content in PHP is forgetting to properly escape the output, which can lead to security vulnerabilities such as XSS attacks. To solve this issue, always use the htmlspecialchars function to escape any user input before outputting it to the browser.

// Example of properly escaping output using htmlspecialchars
$userInput = "<script>alert('XSS attack!');</script>";
echo htmlspecialchars($userInput);