2013-03-31 34 views
2

我最近遇到了file_get_contents的问题... 当我使用它从网络中获取网页时,它工作正常,但是当我使用它打开本地页面时,它会输出只有页面中的文字。 即当我用它作为file_get_contents返回html文件中的文本

file_get_contents("http://www.google.com"); 

,并呼应它,我得到了谷歌网页和它的整个结构,但是当我使用

file_get_contents("localfile.html"); 

和回声它只是输出,而不在网页中的文字标签。

+2

总是看看输出的源代码,而不是浏览器的渲染。 – kba

+0

源代码将是完美的。 –

回答

6

这是因为HTML标签被浏览器解析。使用htmlentities这样:

htmlentities(file_get_contents("localfile.html")); 

但有一件事,当你看到文件的来源,它会显示你所需要的。另外,您也可以在textarea内输出。

<textarea><?php echo htmlentities(file_get_contents("localfile.html")); ?></textarea>