What is the recommended function to use in PHP to prevent HTML tags from being executed in user input?

To prevent HTML tags from being executed in user input in PHP, you can use the `htmlspecialchars` function. This function converts special characters in a string to their HTML entities, preventing any HTML tags from being interpreted by the browser. By using `htmlspecialchars` on user input before displaying it on a webpage, you can prevent potential security vulnerabilities such as cross-site scripting (XSS) attacks.

$userInput = "<script>alert('XSS attack!');</script>";
$safeInput = htmlspecialchars($userInput, ENT_QUOTES, 'UTF-8');
echo $safeInput;