How can PHP developers ensure that user-submitted content is displayed safely without executing any potentially harmful HTML code?

To ensure that user-submitted content is displayed safely without executing potentially harmful HTML code, PHP developers can use the `htmlspecialchars()` function to encode special characters in the user input. This function converts characters like <, >, ", ', and & into their respective HTML entities, preventing any HTML code from being executed.

$user_input = &quot;&lt;script&gt;alert(&#039;Hello, World!&#039;);&lt;/script&gt;&quot;;
$safe_input = htmlspecialchars($user_input, ENT_QUOTES);

echo $safe_input;