Complete the code to safely display user input in HTML.
<?php echo htmlspecialchars([1]); ?>Using htmlspecialchars on $_GET['input'] safely escapes user input from URL parameters to prevent XSS.
Complete the code to prevent XSS by escaping output inside an HTML attribute.
<input value="[1]">
Using htmlspecialchars with ENT_QUOTES escapes quotes inside attributes, preventing XSS.
Fix the error in the code that causes XSS vulnerability.
<?php echo [1]; ?>Directly echoing $_GET['comment'] without escaping allows XSS. Using htmlspecialchars fixes this.
Fill in the blank to create a safe HTML list from user input array.
<?php $items = $_GET['items']; echo '<ul>'; foreach ($items as $item) { echo '<li>' . [1] . '</li>'; } echo '</ul>'; ?>
Escaping each item with htmlspecialchars prevents XSS when displaying user input in HTML lists.
Fill in the blank to safely display user input in a JavaScript context inside HTML.
<script> let userInput = '[1]'; console.log(userInput); </script>
Use addslashes to escape quotes and backslashes in PHP output for JavaScript strings to prevent XSS.