得到这个代码:
<?php
$jsonurl = "https://newsapi.org/v1/articles?source=cnn&sortBy=top&apiKey=d8dfc55aa005430c9567416cac34e3fa";
$json = file_get_contents($jsonurl);
var_dump(json_decode($json));
$file = fopen('news.json','w');
fwrite($file, $json);
fclose($file);
Run Code Online (Sandbox Code Playgroud)
但没有任何内容被保存到新news.json文件中,这是为什么呢?正如我所学到的 - 创建文件是使用这种方法完成的。(w在fopen)