等价于file_get_contents()的函数? [英] Equivalent function for file_get_contents()?

查看:77
本文介绍了等价于file_get_contents()的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从html页面中解析一些信息. 目前,我正在解决以下问题:

I want to parse some information out of a html page. Currently I solve the problem like this:

header("Content-type: text/plain");    
$this->pageSource = file_get_contents ($this->page);
header("Content-type: text/html");

$this->page是网站的网址. 这在XAMPP上可以正常工作,但是当我将脚本上载到Web服务器时,出现以下错误消息:

$this->page is the url of the website. This works fine on XAMPP, but when I upload my script on my webserver, I get the following error message:

警告:file_get_contents()[function.file-get-contents]:服务器配置中通过allow_url_fopen = 0禁用了http://包装器

Warning: file_get_contents() [function.file-get-contents]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0

显然,我不允许在我的Web服务器上执行该功能.

So obviously I am not allowed to execute that function on my webserver.

那么有等效的功能来解决我的问题吗?

So is there an equivalent function to solve my problem?

推荐答案

实际上并未禁用功能file_get_contents
但是allow_url_fopen被禁用

Actually the function file_get_contents is not disabled,
but allow_url_fopen is disabled

您可以将其替换为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也无济于事

However, if you server block outgoing traffic, curl does not help too

这篇关于等价于file_get_contents()的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆