How can PHP developers ensure that only plain text is displayed from user input without converting HTML tags?

To ensure that only plain text is displayed from user input without converting HTML tags, PHP developers can use the htmlentities() function to encode the user input before displaying it. This function will convert special characters to their HTML entities, preventing any HTML tags from being interpreted by the browser.

$userInput = "<b>Hello</b> World!";
$plainText = htmlentities($userInput);
echo $plainText;