How can PHP be used to display HTML code without executing it on a webpage?

To display HTML code without executing it on a webpage using PHP, you can use the htmlspecialchars function to escape special characters in the HTML code. This will prevent the browser from interpreting the HTML code as actual markup and instead display it as plain text. By using this function, you can safely display HTML code on a webpage without it being executed.

<?php
$htmlCode = "<h1>Hello, world!</h1>";
echo htmlspecialchars($htmlCode);
?>