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

问题描述:

I've got this piece of code, which should fetch the source code of the website.

我有这段代码,应该读取网站的源代码。 ( 'http://homepage.com');
echo $ homepage;

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

而不是实际给我的源代码。它显示我正在尝试的页面获取源代码。

Instead of actually giving me the source code.. It's shows me the page that I'm trying to get the source code from.

使用 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;