What are the common pitfalls when trying to modify text appearance in PHP?

One common pitfall when trying to modify text appearance in PHP is not properly escaping special characters, which can lead to unexpected output or security vulnerabilities. To solve this issue, always use functions like htmlspecialchars() to escape special characters before outputting text to the browser.

$text = "<script>alert('Hello!');</script>";
echo htmlspecialchars($text);