file_get_contents 不起作用?
此代码不适用于服务器。但它正在我的本地主机(xampp)上工作,
$url = file_get_contents('http://www.site.com/');
$xhtml='|<tr style="background-color:#dddddd;">
<td class="odd" align="left">(.+?)</td><td class="odd">(.+?)</td>
</tr>|i';
preg_match_all($xhtml,$url,$score);
array_shift($score);
echo"<pre>";
print_r($score);
echo"</pre>";
当我像这样更改代码时,它会打印另一个分数。因为有两行是这样的。它具有相同的代码。通过下面的代码对服务器起作用。
$xhtml='|<td class="odd" align="left">(.+?)</td><td class="odd">(.+?)</td>|i';
我需要在代码之间获取这两个值。
allow_url_fopen = on
This code is not working to server. But It is working to my localhost (xampp)
$url = file_get_contents('http://www.site.com/');
$xhtml='|<tr style="background-color:#dddddd;">
<td class="odd" align="left">(.+?)</td><td class="odd">(.+?)</td>
</tr>|i';
preg_match_all($xhtml,$url,$score);
array_shift($score);
echo"<pre>";
print_r($score);
echo"</pre>";
It prints another scores when I change the code like this. Because there are two rows like this. It has same codes. by the way below code works to server.
$xhtml='|<td class="odd" align="left">(.+?)</td><td class="odd">(.+?)</td>|i';
I need to take this two values between code.
allow_url_fopen = on
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
尝试用此函数代替 file_get_contents():
它可以像 file_get_contents() 一样使用,但使用 cURL。
在 Ubuntu(或其他具有 aptitude 的类 UNIX 操作系统)上安装 cURL:
另请参阅 cURL
Try this function in place of file_get_contents():
It can be used just like file_get_contents(), but uses cURL.
Install cURL on Ubuntu (or other unix-like operating system with aptitude):
See also cURL
您需要
在 php.ini 配置文件中允许。出于安全考虑,某些主机不允许这样做
You need to allow
in your php.ini config file. Some hosts disallow it for security
我知道这个话题已经很老了,但我必须自己解决这个问题,并认为它会对以后的人有所帮助。
就像上面说的:
你需要:
允许 url fopen
允许 url include
如果您使用 CURL 那么您需要curl 扩展
如果您是 https:// 的 file_get_contents 我相信您还需要 apache ssl 模块以及 openssl php 扩展。
如果没有 OpenSSL 和 SSL 模块在 facebook 图上执行 file_get_contents(显然是 https://),它会返回“未找到文件”错误。
I know this topic is old, but I had to figure this out on my own and figure it will help someone later.
Like the above says:
You need:
allow url fopen
allow url include
If you are using CURL then you need curl extension
If you are file_get_contents of a https:// I believe you also need apache ssl module, as well as openssl php extension.
Without OpenSSL and SSL Module doing a file_get_contents on a facebook graph (obviously https://) it returned "No file found" error.
另请检查您是否启用了:allow_url_include On
并确保不存在诸如 403 Forbidden 之类的网络权限问题。
Also check whether you have: allow_url_include On
And make sure that there are no network permission issues like 403 Forbidden.
我们遇到了这个问题,结果发现这是不寻常的事情。我们试图 file_get_contents('https://www.google.com');我们遇到的问题是因为服务器设置为使用 ipv6,但没有分配 ipv6 IP。我们禁用了 ipv6 并让它使用 ipv4 并且它起作用了。清单上还有另一件事需要检查。
We had this issue and it turned out to be something unusual. We were trying to file_get_contents('https://www.google.com'); the issue for us was because the server was set to use ipv6 but it had no ipv6 ip assigned. We disabled ipv6 and had it use ipv4 and it worked. Just another thing on the list to check.
如果
allow_url_fopen
为On
,则禁用您的防火墙或csfIf
allow_url_fopen
isOn
then disable your firewall or csf and check again.