How can PHP codes be displayed as plain text within <pre> tags?

To display PHP codes as plain text within <pre> tags, you can use the htmlspecialchars function to escape special characters in the PHP code before outputting it within the <pre> tags. This will prevent the PHP code from being executed and instead display it as plain text on the webpage.

&lt;?php
$phpCode = &#039;&lt;?php echo &quot;Hello, World!&quot;; ?&gt;&#039;;
echo &#039;&lt;pre&gt;&#039; . htmlspecialchars($phpCode) . &#039;&lt;/pre&gt;&#039;;
?&gt;