Kevin
Kevin

Reputation: 928

Printing raw code on page

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?

Upvotes: 0

Views: 838

Answers (1)

Kirsty Wright
Kirsty Wright

Reputation: 106

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>"; 
?>

Upvotes: 2

Related Questions