Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从解码为普通数组的JSON访问未列出的条目_Php_Json_File Get Contents - Fatal编程技术网

Php 从解码为普通数组的JSON访问未列出的条目

Php 从解码为普通数组的JSON访问未列出的条目,php,json,file-get-contents,Php,Json,File Get Contents,我无法打印电影的运行时间。我可以让它打印实际的网站,但不是我需要的信息从网站 除此之外,如果我删除true json_decode($imdb_json,true) 我得到这个错误 致命错误:无法将stdClass类型的对象用作数组 我如何编写它,以便它正确地从数组中获取数据?我还需要将标题中的空格和破折号(如blacksheep,blacksheep)交换为Black%20Sheep?这样做。。。由于要将JSON转换为数组(通过在JSON\u decode()中传递true),因此需要像数组一

我无法打印电影的运行时间。我可以让它打印实际的网站,但不是我需要的信息从网站

除此之外,如果我删除
true

json_decode($imdb_json,true)

我得到这个错误

致命错误:无法将stdClass类型的对象用作数组


我如何编写它,以便它正确地从数组中获取数据?我还需要将标题中的空格和破折号(如
blacksheep
blacksheep
)交换为
Black%20Sheep

这样做。。。由于要将JSON转换为数组(通过在
JSON\u decode()
中传递true),因此需要像数组一样访问它

$tempmoviename = "Battleship";
$omdburl = "http://www.omdbapi.com/?t=" . $tempmoviename;
$imdb_json = file_get_contents($omdburl);
$imdb_info = json_decode($imdb_json,true);
print ($imdb_info[0]->runtime[0]);

请发布一个在
$imdb\u JSON
中返回并解码为
$imdb\u info
的JSON示例。当然,如果删除第二个参数并继续尝试在对象上使用数组索引执行
$imdb_info[0]
,它会抱怨。您需要查看
htmlspecialchars()
了解您的第二个要求。谢谢。这确实有效。现在我如何从数组中提取电影名称呢?谢谢大家。让我来看看htmlspecialchars()和preg_replace()
<?php
$tempmoviename = "Battleship";
$omdburl = "http://www.omdbapi.com/?t=" . $tempmoviename;
$imdb_json = file_get_contents($omdburl);
$imdb_info = json_decode($imdb_json,true);

echo $imdb_info['Runtime']; //"prints" 131 min