2012-04-15 38 views
0

我使用IMDB API獲取值

$homepage = file_get_contents('http://www.imdbapi.com/?i='.$imdbID); 
      $arr = json_decode($homepage); 

在$改編我對電影相關的所有數據。

Maguire [Year] => 1996 [Rated] => R [Released] => 13 Dec 1996 [Genre] => Comedy, Drama, Romance, Sport [Director] => Cameron Crowe [Writer] => Cameron Crowe [Actors] => Tom Cruise, Cuba Gooding Jr., Renée Zellweger, Kelly Preston [Plot] => When a sports agent has a moral epiphany and is fired for expressing it, he decides to put his new philosophy to the test as an independent with the only athlete who stays with him. [Poster] => http://ia.media-imdb.com/images/M/[email protected]@._V1_SX320.jpg [Runtime] => 2 hrs 19 mins [Rating] => 7.2 [Votes] => 97329 [ID] => tt0116695 [Response] => True) 

我想要的是達到指定鍵的價值。

有沒有這樣的功能?例如,我會給鑰匙=>演員並獲得所有演員?

+0

你能解釋更多你的問題嗎? – 2012-04-15 22:36:05

回答

2

:/喜歡這個?

$homepage = file_get_contents('http://www.imdbapi.com/?i='.$imdbID); 
$arr = json_decode($homepage, true); 
print($arr['Actors']); 
+0

print_r($ arr ['Actors']);什麼都不打印:S – 2012-04-15 22:36:25

+0

確保你傳遞第二個參數(true)給json_decode(); – ezakto 2012-04-15 22:38:01