What are some common pitfalls to avoid when trying to format text output in PHP code?
One common pitfall to avoid when formatting text output in PHP is forgetting to properly escape special characters to prevent injection attacks. To solve this issue, always use functions like htmlspecialchars() to encode special characters before outputting text to the browser.
$text = "<script>alert('Hello');</script>";
echo htmlspecialchars($text);