How can PHP developers handle HTML tags in user input to prevent security risks?

PHP developers can handle HTML tags in user input by using the `htmlspecialchars()` function to convert special characters to HTML entities. This prevents potential security risks such as Cross-Site Scripting (XSS) attacks by rendering any HTML tags harmless. By sanitizing user input in this way, developers can ensure that any HTML tags entered by users are displayed as plain text rather than being interpreted as code.

$user_input = '<script>alert("XSS attack!");</script>';
$sanitized_input = htmlspecialchars($user_input, ENT_QUOTES);
echo $sanitized_input;