How can XSS vulnerabilities be addressed in PHP code that handles form submissions?

XSS vulnerabilities in PHP code that handles form submissions can be addressed by sanitizing user input before displaying it on the webpage. This can be done by using functions like htmlspecialchars() to encode special characters that could be used in an XSS attack.

// Sanitize user input before displaying it on the webpage
$user_input = htmlspecialchars($_POST['user_input']);

// Use the sanitized input in your PHP code
echo "User input: " . $user_input;