How to display HTML tags as plain text

Here is the top answer of How to display HTML tags as plain text

<?php
$patterns = array();
$patterns[0] = '/</';
$patterns[1] = '/>/';
$replacements = array();
$replacements[2] = '&lt;';
$replacements[1] = '&gt;';
preg_replace($patterns, $replacements, $string);
?>

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

Leave a Comment