【问题标题】:issue with file_get_contents in json fetchjson fetch 中的 file_get_contents 问题
【发布时间】:2013-05-12 06:13:33
【问题描述】:

以下来自另一个问题:Handling data in a PHP JSON Object

$jsonurl     = "http://search.twitter.com/trends.json";
$json        = file_get_contents($jsonurl, 0, null, null);
$json_output = json_decode($json);

foreach ($json_output->trends as $trend)
{
    echo "{$trend->name}\n";
}

我的问题:这两者有什么区别:

file_get_contents($jsonurl,0,null,null)
file_get_contents($jsonurl)

我检查了file_get_contents() PHP manual,但仍然不完全理解它,换句话说,如果我使用这一行:

file_get_contents($jsonurl)

会发生什么?

【问题讨论】:

    标签: php json file-get-contents


    【解决方案1】:

    它将使用默认参数(falsenull-1null)。在您的情况下,您的操作几乎相同(0 评估为false,第二个null 没有参数,所以-1)。

    所以最好只使用file_get_contents($jsonurl);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-13
      • 2011-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-12
      相关资源
      最近更新 更多