简体   繁体   English

json fetch中的file_get_contents问题

[英]issue with file_get_contents in json fetch

The following is from another question: Handling data in a PHP JSON Object : 以下是另一个问题: 处理PHP JSON对象中的数据

$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";
}

My Question: What is the difference between those two: 我的问题:这两者有什么区别:

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

I checked file_get_contents() PHP manual , but still do not totally understand it, in another words, if i use this line: 我检查了file_get_contents() PHP手册 ,但仍然不完全理解它,换句话说,如果我使用这一行:

file_get_contents($jsonurl)

What will happen? 会发生什么?

It will use default parameters ( false , null , -1 , null ). 它将使用默认参数( falsenull-1null )。 In your case you do almost the same ( 0 evaluates as false , the second null as no parameter, so -1 ). 在你的情况下,你做的几乎相同( 0评估为false ,第二个null为无参数,因此为-1 )。

So better use just file_get_contents($jsonurl); 所以最好只使用file_get_contents($jsonurl);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM