file_get_contents 不起作用?

发布于 2024-12-10 05:22:35 字数 664 浏览 0 评论 0原文

此代码不适用于服务器。但它正在我的本地主机(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

我为君王 2024-12-17 05:22:35

尝试用此函数代替 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

Try this function in place of 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;
}

It can be used just like file_get_contents(), but uses cURL.

Install cURL on Ubuntu (or other unix-like operating system with aptitude):

sudo apt-get install php5-curl
sudo /etc/init.d/apache2 restart

See also cURL

无人接听 2024-12-17 05:22:35

您需要

 allow_url_fopen

在 php.ini 配置文件中允许。出于安全考虑,某些主机不允许这样做

You need to allow

 allow_url_fopen

in your php.ini config file. Some hosts disallow it for security

世界等同你 2024-12-17 05:22:35

我知道这个话题已经很老了,但我必须自己解决这个问题,并认为它会对以后的人有所帮助。

就像上面说的:

你需要:

允许 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.

荒人说梦 2024-12-17 05:22:35

另请检查您是否启用了: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.

百变从容 2024-12-17 05:22:35

我们遇到了这个问题,结果发现这是不寻常的事情。我们试图 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.

删除→记忆 2024-12-17 05:22:35

如果allow_url_fopenOn,则禁用您的防火墙csf

If allow_url_fopen is On then disable your firewall or csf and check again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文