- PHP

How to display HTML code as Text

Replace < with &lt; and > with &gt;.

Example:

&lt;center&gt;Hello&lt;/center&gt;

Output:

<center>Hello</center>

Displaying HTML code as text in PHP

Use htmlspecialchars() function in PHP.

If you want to display HTML code as text in PHP, the easiest way to do so is to use htmlspecialchars() function.

Example:

<?php echo htmlspecialchars('<strong>Hello</strong>'); ?>

Output:

<strong>Hello</strong>