What are the potential security risks of allowing HTML input in text fields in PHP?

Allowing HTML input in text fields in PHP can lead to security risks such as cross-site scripting (XSS) attacks, where malicious scripts are injected into the webpage and executed in the context of the user's browser. To prevent this, you can use the `htmlspecialchars()` function to escape special characters in the input before displaying it on the webpage.

// Escape HTML input before displaying it on the webpage
$input = "<script>alert('XSS attack!');</script>";
$escaped_input = htmlspecialchars($input, ENT_QUOTES, 'UTF-8');
echo $escaped_input;