Are there any potential pitfalls or security risks when using htmlspecialchars() with ENT_NOQUOTES in PHP for XSS protection?

Using htmlspecialchars() with ENT_NOQUOTES in PHP for XSS protection can still leave your application vulnerable to certain types of XSS attacks, such as attribute-based XSS. To mitigate this risk, it is recommended to use ENT_QUOTES instead, which will encode both double and single quotes. This will help prevent attackers from injecting malicious scripts into your application.

// Original code using htmlspecialchars() with ENT_NOQUOTES
$unsafe_input = '<script>alert("XSS attack!")</script>';
$safe_output = htmlspecialchars($unsafe_input, ENT_NOQUOTES);

// Updated code using htmlspecialchars() with ENT_QUOTES for better XSS protection
$safe_output = htmlspecialchars($unsafe_input, ENT_QUOTES);