Php - print html tags as text

html, php, tags

Solution

Basically all you really need to make HTML readable as text is:

$out = strtr($input,Array("<"=>"&lt;","&"=>"&amp;"));

`htmlspecialchars` is basically a subset of `htmlentities`. `htmlentities` encodes EVERYTHING that has an entity alternative, namely all the named entities and a handful of codes.

Problem

I need to print an HTML tag on screen as texts (and not in code). I need the readers to literally read the tag. What is the best practice to do so ? ``` print htmlspecialchars('<meta name="copyright" content="© Winston Smith, 1984">'); ``` or ``` print htmlentities('<meta name="copyright" content="© Winston Smith, 1984">'); ``` or none of the above. - Is there a better way? - What else should I consider ? - And last question - should I use print, echo or is there no difference ? *EDIT I* I already seen a problem with the character "©" with htmlentities(). This only confirms my doubts - which one is safe to use for all cases - and is there another way to print html tags as text ?

Original source