What are the common pitfalls in HTML usage within PHP scripts and how can they affect script functionality?
Common pitfalls in HTML usage within PHP scripts include improperly escaping HTML characters, which can lead to security vulnerabilities like cross-site scripting (XSS) attacks. To prevent this, always use functions like htmlspecialchars() to escape HTML characters when outputting user input. Example PHP code snippet:
$user_input = "<script>alert('XSS attack');</script>";
echo htmlspecialchars($user_input, ENT_QUOTES, 'UTF-8');