Complete the code to escape special HTML characters in the string.
<?php $text = "<script>alert('Hi');</script>"; echo [1]($text); ?>
The htmlspecialchars function converts special characters to HTML entities, preventing code injection in HTML output.
Complete the code to escape special characters and convert quotes to HTML entities.
<?php $text = 'He said "Hello" & left.'; echo htmlspecialchars($text, [1]); ?>
The ENT_QUOTES flag converts both double and single quotes to HTML entities.
Fix the error in the code to properly escape the output with UTF-8 encoding.
<?php $text = '<b>Bold</b> & "Quotes"'; echo htmlspecialchars($text, ENT_QUOTES, [1]); ?>
Using "UTF-8" ensures correct encoding of multibyte characters when escaping HTML.
Fill both blanks to escape the string and prevent double encoding.
<?php $text = '<a href="test">Link</a>'; echo htmlspecialchars($text, [1], 'UTF-8', [2]); ?>
Use ENT_QUOTES to escape quotes and false to prevent double encoding.
Fill all three blanks to create a safe HTML output with escaped text and a newline converted to <br>.
<?php $text = "Hello & welcome\nHave a nice day!"; $safe_text = nl2br(htmlspecialchars([1], [2], [3])); echo $safe_text; ?>
Escape the variable $text with ENT_QUOTES and "UTF-8" encoding, then convert newlines to <br> tags.