[英]file_get_contents not working?
此代码不适用于服务器。 但它正在我的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>";
当我像这样更改代码时,它会打印另一个分数。 因为这样有两行。 它有相同的代码。 顺便说一句下面的代码工作到服务器。
$xhtml='|<td class="odd" align="left">(.+?)</td><td class="odd">(.+?)</td>|i';
我需要在代码之间取两个值。
allow_url_fopen = on
尝试使用此函数代替file_get_contents():
<?php
function curl_get_contents($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
它可以像file_get_contents()一样使用,但使用cURL。
在Ubuntu(或其他具有aptitude的类Unix操作系统)上安装cURL:
sudo apt-get install php5-curl
sudo /etc/init.d/apache2 restart
另见cURL
你需要允许
allow_url_fopen
在你的php.ini配置文件中。 有些主机因安全性而不允许它
我知道这个话题已经过时了,但我必须自己解决这个问题,并认为它会在以后对某人有所帮助。
如上所述:
你需要:
允许url fopen允许url include
如果您使用CURL,则需要卷曲扩展
如果您是https://的file_get_contents,我相信您还需要apache ssl模块,以及openssl php扩展。
如果没有OpenSSL和SSL模块在facebook图表上执行file_get_contents(显然是https://),则会返回“No file found”错误。
还要检查你是否: allow_url_include On
并确保没有像403 Forbidden这样的网络权限问题。
我们遇到了这个问题,结果证明这是不寻常的。 我们正在尝试使用file_get_contents(' https://www.google.com '); 我们的问题是因为服务器设置为使用ipv6但没有分配ipv6 ip。 我们禁用了ipv6并让它使用ipv4并且它有效。 列表上的另一件事就是检查。
如果allow_url_fopen
为On
则禁用防火墙或csf并再次检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.