Display user text safely
Take your time, follow the code and check your understanding.
The codePHP arrays and requests
<?php echo $name; ?>Your answer4 min · no timer
Show solution and explanation
Use context-appropriate escaping when outputting user text into HTML. htmlspecialchars handles the HTML text context; other contexts need their own handling.
Escape HTML output with htmlspecialchars($name, ENT_QUOTES | ENT_SUBSTITUTE, "UTF-8").