使用File_Get_Contents抓取站点,然后删除标题并显示站点


Use File_Get_Contents to grab site, then remove header and display site?

在下面的代码中,我尝试使用文件获取内容命令来获取网站内容并输出它,但是当我运行它时显示一个空白页面。

<html>
<?php 
$site = "http://facebook.com";
echo $file_get_contents[$site];
?>
<html>
在此之后,我想使用
header('X-Frame-Options: GOFORIT');

或类似的编辑标题,但第一个代码显示网页不工作,所以会是什么错误?

这可能行得通,但我想这需要SSL之类的东西,详细了解file_get_contents,因为

file_get_contents() -将整个文件读入字符串

因为它是一个函数而不是你在代码中使用的数组。

<?php 
$site = "http://facebook.com";
echo file_get_contents($site); // remove $ from file_get_contents() function
?>

正确的用法是file_get_contents()。它是一个函数——你把它作为一个哈希变量来调用。只是一个语法问题。请参阅下面的正确用法:

<html>
<?php 
$site = "http://facebook.com";
echo file_get_contents($site);
?>
<html>

阅读file_get_contents文档获取更多信息:http://php.net/manual/en/function.file-get-contents.php

有两点需要改变。1. 删除file_get_content()前面的$,因为它是一个函数。2. 因为它是一个函数,参数是使用()而不是[],这意味着一个数组,下次请尝试并发布错误消息,这将有助于快速看到代码的问题;

<html>
<?php 
$site = "http://facebook.com";
echo file_get_contents($site);
?>
<html>
  • 添加header('X-Frame-Options: GOFORIT');将允许您将页面加载到您想要的iframe中。