Q:

php echo html tag so it is viewable (not interpreted as code)

I am currently trying to echo a text value from a variable which contains html-style tags. <...> 
$string = "variable_name";
$tag_str = "<".$string.">";
echo $tag_str;

currently this echo's as nothing as it believes it is html code. How would I go about echoing <variable_name> to the page so it is viewable and not interpreted as code by the browser?

A:

You'll have to html encode your output
$string = "variable_name";
$tag_str = "<".$string.">";
echo htmlspecialchars($tag_str);

