Php 文件_get_contents()的等效函数?
我想从html页面中解析一些信息。 目前我解决的问题是这样的:Php 文件_get_contents()的等效函数?,php,file-get-contents,Php,File Get Contents,我想从html页面中解析一些信息。 目前我解决的问题是这样的: header("Content-type: text/plain"); $this->pageSource = file_get_contents ($this->page); header("Content-type: text/html"); $this->page是网站的url。 这在XAMPP上运行良好,但当我在Web服务器上上载脚本时,会收到以下错误消息: 警告:file_get_contents()
header("Content-type: text/plain");
$this->pageSource = file_get_contents ($this->page);
header("Content-type: text/html");
$this->page
是网站的url。
这在XAMPP上运行良好,但当我在Web服务器上上载脚本时,会收到以下错误消息:
警告:file_get_contents()[function.file get contents]:http://wrapper在服务器配置中被allow_url_fopen=0禁用
很明显,我不允许在我的Web服务器上执行该函数
那么有没有一个等价的函数来解决我的问题呢?使用。是常用的标准解决方案。使用
curl
为什么需要将标题更改为纯文本来检索数据?如果您正在检索数据,则无需执行此操作。实际上,功能文件获取内容
未被禁用,但是
allow\u url\u fopen
被禁用
您可以将其替换为curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->page);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$this->pageSource = curl_exec($ch);
curl_close($ch);
但是,如果您的服务器阻止传出流量,
curl
也没有帮助如果您有curl,请使用它,这非常有用
$urlx = 'http://yoururl';
$data="from=$from&to=$to&body=".urlencode($body)."&url=$url";
//set post parameters
$process = curl_init($urlx);
//init curl connection
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_POSTFIELDS, $data);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_RETURNTRANSFER,1);
curl_setopt($process,CURLOPT_CONNECTTIMEOUT,1);
$resp = curl_exec($process);
//your content
curl_close($process);
您可以使用该函数,但不能与URL一起使用,只能与本地文件一起使用,这是错误消息告诉您的。
file\u get\u contents()?