Q:

file_get_contents returns the text in an html file

I am facing a problem with file_get_contents recently...
When I use it to fetch webpages from the web, it works fine, but when I use it to open a local page it outputs only the text in the page.
i.e. when I use it as
file_get_contents("http://www.google.com");  

and echo it I get the google page and its entire structure but when I use 
file_get_contents("localfile.html"); 

and echo it it just outputs the text in the page without the tags. 

A:

It is because, HTML tags are parsed by the browser. Use htmlentities this way:
htmlentities(file_get_contents("localfile.html"));

But one thing, when you see the source of the file, it shows you what you need. Also, alternatively you can output this inside a textarea.
<textarea><?php echo htmlentities(file_get_contents("localfile.html")); ?></textarea>

