通过Json方式获取API电影接口

php php 1094      收藏
通过Json方式获取API电影接口

<?php 
header("content-type:text/html;charset=utf8");

if(isset($_POST['submit'])){
$city=urlencode($_POST['city']);
$url="http://api.map.baidu.com/telematics/v3/movie?qt=hot_movie&location={$city}&ak=fCWHp1a9QdsHwfPbHZ20LGLzgpKHEGrc&output=json";

$result=file_get_contents($url);
// echo"<pre>";
// va_dump($result);
$result =json_decode($result,true);
//echo"<pre>";
//var_dump($result) ;
}

 ?>
 <!DOCTYPE html>
 <html>
 <head>
  <meta charset="UTF-8">
  <meta name="kalven" content="content">
  <title>获取电影信息</title>
 </head>
 <body>
  <form action="" method="POST" >
<p><span>输入城市:</span><input type="text" name="city" value="<?php echo isset($_POST['city'])?$_POST['city']:'';?>"> <input type="submit" name="submit" value="点击搜索"></p>
<div>
<?php  
if (isset($result) && $result["error"]==0) {
$movies=$result['result']['movie'];
foreach ($movies as $movie) {
$url=$movie['movie_picture'];
echo "电影名称:<strong style='color:red'>".$movie['movie_name']."</strong><br/>";
echo "上映时间:".$movie['movie_release_date']."<br/>";
echo "电影国家:".$movie['movie_nation']."<br/>";
echo "领衔主演:".$movie['movie_starring']."<br/>";
echo "<img src='{$url}' alt=''>";
echo "<hr/>";
}
}
?>
</div>
  </form>
 </body>
 </html>