file_get_contents无法正常工作?

Ven*_*nom 15 php regex file-get-contents

此代码不适用于服务器.但它正在我的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>";
Run Code Online (Sandbox Code Playgroud)

当我像这样更改代码时,它会打印另一个分数.因为这样有两行.它有相同的代码.顺便说一句下面的代码工作到服务器.

$xhtml='|<td class="odd" align="left">(.+?)</td><td class="odd">(.+?)</td>|i';
Run Code Online (Sandbox Code Playgroud)

我需要在代码之间取两个值.

allow_url_fopen = on
Run Code Online (Sandbox Code Playgroud)

Ade*_*mar 27

尝试使用此函数代替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;
}
Run Code Online (Sandbox Code Playgroud)

它可以像file_get_contents()一样使用,但使用cURL.

在Ubuntu(或其他具有aptitude的类Unix操作系统)上安装cURL:

sudo apt-get install php5-curl
sudo /etc/init.d/apache2 restart
Run Code Online (Sandbox Code Playgroud)

另见cURL


gen*_*sis 19

你需要允许

 allow_url_fopen
Run Code Online (Sandbox Code Playgroud)

在你的php.ini配置文件中.有些主机因安全性而不允许它


Dav*_*nce 10

我知道这个话题已经过时了,但我必须自己解决这个问题并认为它会在以后对某人有所帮助.

如上所述:

你需要:

允许url fopen允许url include

如果您使用CURL,则需要卷曲扩展

如果您是https://的file_get_contents,我相信您还需要apache ssl模块,以及openssl php扩展.

如果没有OpenSSL和SSL模块在facebook图表上执行file_get_contents(显然是https://),则会返回"No file found"错误.