1. Home
  2. Computer Science MCQs
  3. PHP
  4. Which function helps prevent XSS attacks when printing…

Added 2 Nov 2026

Which function helps prevent XSS attacks when printing user input into HTML?

  1. urlencode_html()
  2. htmlspecialchars() Correct answer
  3. mysqli_escape()
  4. strip_tags_all()

Correct answer

B. htmlspecialchars()

12 views

MCQSEXAM

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

Preparing for an exam?

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More PHP MCQs

Practise all PHP MCQs

Similar MCQs