IMDB API to php variables


IMDB API to php variables

stackoverflow用户你好。我需要从开放的电影数据库API拉一些电影信息。他们没有关于如何使用他们的API的文档,所以我很困惑。我在PHP创建的网站需要从他们的api拉一些变量或字符串取决于什么imdb ID我放在一个形式。这是我到目前为止得到的代码。这给了我:"http://www.omdbapi.com/?i=tt1092026"。但我需要得到他们的API的字符串,使它们成为变量,这样我就可以在以后的形式中使用它们。我该怎么做呢?请帮助。谢谢!: D

<form action="?action=grab" method="post">
<input placeholder="tt1092026" type="text" name="id" id="id">
<input type="submit" class="button" value="Grab Movie">
</form>
<?php if ($_GET[action] == "grab") { ?>
<h9>
<?php
$id = $_POST["id"];
$url = "http://www.omdbapi.com/?i=$id";
echo $url;
?>
</h9>
<?php }; ?>

您需要解码响应并将其分配给变量(全部在PHP中)。

<?php
$id = $_POST["id"];
$url = file_get_contents("http://www.omdbapi.com/?i=$id");
$json = json_decode($url, true); //This will convert it to an array
$movie_title = $json['Title'];
$movie_year = $json['Year'];
//and so on...

,然后当你需要回显它们时:

echo $movie_title;

echo "The movie '$movie_title' was made in $movie_year.";

我认为TMDB是一个更好的API。http://www.themoviedb.org他们有很好的文档:http://docs.themoviedb.apiary.io

我在我自己的web应用程序中使用它,它像一个魅力。