What function in PHP can be used to prevent HTML or PHP code from being executed when entered into an input field?

To prevent HTML or PHP code from being executed when entered into an input field, you can use the htmlspecialchars() function in PHP. This function converts special characters to their HTML entities, preventing any code from being interpreted by the browser.

$input = "<script>alert('Hello');</script>";
$safe_input = htmlspecialchars($input);
echo $safe_input;