Printing raw code on page

时间:2016-10-19 13:34:41

标签: php html

I'm trying to print raw html with PHP like this:

<?php
$head = htmlspecialchars('<head></head>',ENT_QUOTES);
echo $head; 
?>

This works nothing wrong with it if you are willing to print this ammount of html.

The problem is what if i want to print alot of html. Look at the picture below:

enter image description here

It comes out really messy. I want to add some line breaks in between, but if i do this it will just print <br/> right?

1 个答案:

答案 0 :(得分:2)

You can wrap your html output in <pre> tags to keep the intial formatting.

So your code would change to :

<?php
$head = htmlspecialchars('<head></head>',ENT_QUOTES);
echo "<pre>".$head."</pre>"; 
?>