Back to questions
JuniorTheoryCommon
What does the program print?
<?php
$name = '<b>Ann</b> & "co"';
echo htmlspecialchars($name), "\n";<b>Ann</b> & "co"
- Expecting quotes to stay as they are when no flag is passed: the default flags encode
"as", and since PHP 8.1 they includeENT_QUOTES, so'becomes'too. - Expecting
htmlspecialcharsto strip the tags: it removes nothing, it turns<and>into<and>, and the browser then shows the tag as text.
- What does the browser show on the page when this output is placed inside
<p>? - What happens if you call
htmlspecialcharstwice on the same string?