Which function helps prevent XSS attacks when printing user input into HTML?
A
urlencode_html()
B
htmlspecialchars()
Correct answer
C
mysqli_escape()
D
strip_tags_all()
Correct answer
B. htmlspecialchars()
13 views
⚔️
Challenge a friend on PHP
Same MCQs, timed, live leaderboard. Send the link on WhatsApp – no sign-up needed.
Create challenge
Explanation
htmlspecialchars() converts characters such as , &, " and ' into HTML entities, so injected script tags are displayed as text instead of being executed.
Reference
Asked in: NTS, PHP Developer Interviews
Doubts & discussionNot sure why the answer is B? Ask here and get an explanation.
Ask a doubt about this MCQ
‹ Previous MCQ In PHP, what does the spaceship operator expression 3 <=> 7 return? Next MCQ › Which function, added in PHP 8.0, checks whether a string contains a given substring?