Sometimes, we want to display HTML tags as plain text with PHP.
In this article, we’ll look at how to display HTML tags as plain text with PHP.
How to display HTML tags as plain text with PHP?
To display HTML tags as plain text with PHP, we can use the htmlspecialchars
function.
For instance, we write
echo "<pre>";
echo htmlspecialchars($YOUR_HTML);
echo "</pre>";
to call htmlspecialchars
with $YOUR_HTML
to return a string with all the HTML characters escaped.
Then we can wrap the string with pre tags to display the HTML text as code.
Conclusion
To display HTML tags as plain text with PHP, we can use the htmlspecialchars
function.