How can the code provided be modified to prevent XSS vulnerabilities in PHP?

To prevent XSS vulnerabilities in PHP, it is important to properly sanitize user input before displaying it on a webpage. One way to do this is by using the htmlspecialchars() function to convert special characters into HTML entities, which will prevent any malicious scripts from being executed.

<?php
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);

echo "Hello, $name! Your email is $email.";
?>