How can PHP be used to output HTML code as text?
To output HTML code as text using PHP, you can use the htmlspecialchars function to encode the HTML tags as text. This ensures that the HTML tags are displayed as text on the webpage rather than being rendered as actual HTML elements. By using this function, you can prevent any potential security vulnerabilities that may arise from user input containing HTML code.
<?php
$htmlCode = "<h1>Hello, World!</h1>";
echo htmlspecialchars($htmlCode);
?>