What are some potential pitfalls to avoid when formatting text output in PHP using CSS?
One potential pitfall to avoid when formatting text output in PHP using CSS is not properly escaping the data before outputting it. This can lead to security vulnerabilities such as cross-site scripting attacks. To solve this issue, always use functions like htmlspecialchars() to escape the data before including it in the CSS.
<?php
$text = "<script>alert('XSS attack');</script>";
$escaped_text = htmlspecialchars($text, ENT_QUOTES);
echo "<div style='color: red;'>$escaped_text</div>";
?>