2

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

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

并回显它我得到了谷歌页面及其整个结构但是当我使用

file_get_contents("localfile.html"); 

并回显它,它只输出页面中没有标签的文本。

4

1 回答 1

8

这是因为,HTML 标签是由浏览器解析的。使用htmlentities这种方式:

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

但有一件事,当你看到文件的来源时,它会告诉你你需要什么。此外,您也可以在textarea.

<textarea><?php echo htmlentities(file_get_contents("localfile.html")); ?></textarea>
于 2013-03-31T04:04:19.947 回答