sahossaini
sahossaini

Reputation: 476

How to echo html code file in php?

I want to print exact text files of a file. But, as the file contains HTML code (example: <br/>, <table> etc.) the formatting of the page changes. I want to echo exactly what the file contains, <br/>, <table> etc. printed in the page. How can I do that? Please help.

Upvotes: 1

Views: 152

Answers (2)

Kamehameha
Kamehameha

Reputation: 5488

If you want your whole page that way, then you can set the header to

header('Content-Type:text/plain');

and then echo our file contents.

Upvotes: 1

Make use of htmlentities() [Pretty heavy when compared to htmlspecialchars()]

<?php
echo htmlentities($yourhtmlcontent);

Alternatively, you could make use of htmlspecialchars() too.

Upvotes: 1

Related Questions