file_get_contents 返回 html 文件中的文本

2024-04-16

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

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

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

file_get_contents("localfile.html"); 

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


这是因为,HTML标签是由浏览器解析的。使用htmlentities http://www.php.net/manual/en/function.htmlentities.php这边走:

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

但有一件事,当您看到文件的来源时,它会向您显示您需要的内容。另外,您也可以将其输出到textarea.

<textarea><?php echo htmlentities(file_get_contents("localfile.html")); ?></textarea>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

file_get_contents 返回 html 文件中的文本 的相关文章

随机推荐