How can PHP developers ensure that user input is displayed as entered without executing HTML code?

To ensure that user input is displayed as entered without executing HTML code, PHP developers can use the htmlspecialchars function to convert special characters to HTML entities. This function will prevent any HTML code from being executed and display the user input as plain text on the webpage.

$user_input = "<script>alert('Hello World');</script>";
echo htmlspecialchars($user_input);