php file_get_contents() 显示页面而不是 html 源代码

标签 php html

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

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

而不是实际给我源代码..它向我展示了我试图从中获取源代码的页面。

最佳答案

使用 htmlentities 或更改内容类型。

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

header('Content-type: text/plain');
$homepage = file_get_contents('http://homepage.com/');
echo $homepage;

关于php file_get_contents() 显示页面而不是 html 源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33732830/

相关文章:

html - 从 Bootstrap 中删除 margin ?

html - <tr> 中第一个 <td> 的 CSS 样式

java - 从 html 获取将显示给用户的文本

html - 如何设置页码样式以不与自定义寻呼机中的上一行重叠

php - 当输入是带有 PHP PDO 的数组时,从 $_POST 插入行

php - 比较同一个表中的两个值

php - 带复选框的多次更新 Laravel (LARAVEL 5.2)

php - 如何在使用 PHP 调试在 Visual Code 中调试时设置变量值?

html - 文本不以响应式背景图像为中心

javascript - WordPress 将 javascript 添加到 native WordPress 帖子/页面编辑器