【发布时间】:2019-07-21 11:55:59
【问题描述】:
当我在搜索字段中输入电影名称时,我想显示所有 json 文件的电影,但使用此代码我只能获得其中一部电影,请您帮帮我。
<?php
if (isset($_POST['submit-search'])) {
$txtresult = $_POST['search'];
function getImdbRecord($title, $ApiKey)
{
$path = "http://www.omdbapi.com/?s=$title&apikey=$ApiKey";
$json = file_get_contents($path);
return json_decode($json, TRUE);
}
$data = getImdbRecord($txtresult, "f3d054e8");
echo "<div class = 'info-box'><img src =".$data['Poster']."</img><h3> Name :".$data['Title']."</h3><h3> Year : ".$data['Year']."</h3><h3> Duration : ".$data['Runtime'],"</h3></div>";
}
?>
【问题讨论】: