file_get_contents()无法打开流: [英] file_get_contents() failed to open stream:

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

问题描述

我正在尝试使用file_get_contents()来获取Twitter提要,但是我收到以下警告:

I'm trying to use file_get_contents() to grab a twitter feed, however I'm getting the following warning:

failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request

我的代码:

$feed = 'http://twitter.com/statuses/user_timeline.rss?screen_name=google&count=6';
$tweets = file_get_contents($feed);

我出于测试目的而使用Google.我的php.ini文件中启用了allow_url_fopen.

I'm using Google just for the sake of testing. allow_url_fopen is enabled in my php.ini file.

有什么主意吗?

推荐答案

如果出现以下情况,则应使用 PHP cURL 扩展名它是可用的,因为它快很多倍,更强大并且更易于调试.这是一个与您尝试的操作相同的示例:

You should use the PHP cURL extension if it's available, as it's many times faster, more powerful, and easier to debug. Here is an example that does the same thing you were trying:

function curl($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
}

$feed = 'http://twitter.com/statuses/user_timeline.rss?screen_name=google&count=6';
$tweets = curl($feed);

这篇关于file_get_contents()无法打开流:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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