Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing theMovieDB to display Image Poster with PHP
    text
    copied!<p>I'm new to using the themoviedb JSON api, and I'm currently trying to do something that seems simple: Display a movie's main poster. I got an API key and here is the code / response I'm using.</p> <pre><code>$ca = curl_init(); curl_setopt($ca, CURLOPT_URL, "http://api.themoviedb.org/3/configuration?api_key=MYAPIKEY"); curl_setopt($ca, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ca, CURLOPT_HEADER, FALSE); curl_setopt($ca, CURLOPT_HTTPHEADER, array("Accept: application/json")); $response = curl_exec($ca); curl_close($ca); //var_dump($response); $config = json_decode($response, true); //print_r($config); //$base = $config['base_url']; //echo($base); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://api.themoviedb.org/3/search/movie?query=Monsters+University&amp;api_key=MYAPIKEY"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json")); $response = curl_exec($ch); curl_close($ch); $result = json_decode($response, true); //print_r($result); //var_dump($response); echo("&lt;img src='" . $config[0]['base_url'] . $config[0]['poster_sizes'][2] . $result[0]['poster_path'] . "'/&gt;"); </code></pre> <p>My only question now is I'm trying to echo a tag to display the poster, but I'm not sure what the correct code would be would it be something like this?</p> <pre><code>$responsePHP = json_decode($response); echo("&lt;img src='" . $responsePHP['poster_path'] . "'/&gt;"); </code></pre> <p>Any help would be appreciated!</p> <p><strong>Edit:</strong> Added the config array, but it the echo returns with nothing. The JSON for both print out fine and <code>print_r</code> seems to work with <code>json_decode</code>, I just don't know why I can't pull out any values from the arrays</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload