Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php文件_get_contents()显示页面而不是html源代码_Php_Html - Fatal编程技术网

php文件_get_contents()显示页面而不是html源代码

php文件_get_contents()显示页面而不是html源代码,php,html,Php,Html,我已经有了这段代码,应该可以获取网站的源代码 $homepage = file_get_contents('http://homepage.com'); echo $homepage; 而不是给我源代码。。它向我显示了我试图从中获取源代码的页面。尝试使用以下方法: 这是因为您正在获取源代码并(重新)输出它。您的页面只是镜像http://homepage.com 要查看实际的页面源,请在echo语句之前添加Content-Type标题: header('Content-type: text/pl

我已经有了这段代码,应该可以获取网站的源代码

$homepage = file_get_contents('http://homepage.com');
echo $homepage;
而不是给我源代码。。它向我显示了我试图从中获取源代码的页面。

尝试使用以下方法:


这是因为您正在获取源代码并(重新)输出它。您的页面只是镜像
http://homepage.com

要查看实际的页面源,请在
echo
语句之前添加
Content-Type
标题:

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

这告诉浏览器将源代码视为纯文本,而不是将其解释为HTML。

使用
htmlentities
或更改内容类型

$homepage = file_get_contents('http://homepage.com');
echo htmlentities($homepage);


这是因为您正在打印源代码,您的浏览器会将其解释为网页。要查看实际代码使用情况,请执行以下操作:

echo htmlspecialchars($homepage);

看看网页资料,想一想,这就是我要找的。。谢谢:这对我也很有效。谢谢但是,如果网页中有php代码,我想知道是否有任何解决方案可以显示html代码和php代码?只是古玩!因为我创建了一个简单的登录网站。恐怕有任何解决方案可以查看我在页面中的php代码。这样人们就可以轻松地破解登录详细信息。htmlspecialchars没有帮我完成这项工作。感谢您花时间来帮助我。请问您打算如何处理提取的HTML代码?如果希望在包含其他内容/设计的网页上显示代码,或者希望将其放入表单的文本区域,则需要使用
htmlentities
。如果您设置了标题,那么您将无法在结果页面上显示除文本以外的任何其他内容,因为它基本上与获取名为
index.html
的页面并将其重命名为
index.txt
——它将不再作为代码解析。
header('Content-type: text/plain');
$homepage = file_get_contents('http://homepage.com/');
echo $homepage;
echo htmlspecialchars($homepage);