How can PHP effectively format input to display HTML entities in the browser view?

To effectively format input to display HTML entities in the browser view, you can use the `htmlspecialchars()` function in PHP. This function converts special characters to HTML entities, preventing potential security vulnerabilities such as cross-site scripting (XSS) attacks.

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