我有这段代码,应该可以获取网站的源代码。
$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/