Quick Answer
Output escaping converts special characters so they cannot be interpreted as code. htmlspecialchars() prevents XSS in HTML context. Use json_encode() when outputting JSON. For SQL use prepared statements. For shell commands use escapeshellarg(). Escape at output time in the correct context. Never trust user input in output without escaping. A missed escape can lead to XSS or injection attacks.
Answer
Output escaping prevents XSS by converting special characters using htmlspecialchars() or htmlentities().
S
SugharaIQ Editorial Team
Verified Answer
This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.
PHP interview questions and answers for beginner, junior, mid-level, senior, and expert developers. Ideal for freshers and experienced candidates preparing for PHP roles.