What is the purpose of escaping HTML code in PHP?
Escaping HTML code in PHP is important to prevent cross-site scripting (XSS) attacks. By escaping the HTML code, you can ensure that any user input displayed on a webpage is treated as plain text rather than executable code. This helps to protect your website from malicious scripts that could potentially steal sensitive information or harm your users.
$user_input = "<script>alert('XSS attack!');</script>";
echo htmlspecialchars($user_input, ENT_QUOTES, 'UTF-8');