$key,
'query' => $query,
//'offset' => '0' // optional argument supplies the start index of the first search result
);
//for testing purposes show actual request to API - REMOVE when finished
$apiRequest = $base.http_build_query($params);
echo $apiRequest;
//build request, encode entities (using http_build_query), and send to API
$request = file_get_contents($base.http_build_query($params));
//create json object(s) out of response from API
$data = json_decode($request);
//parse json elements and display as html
if ($data->num_results != 0) {
echo '
Results of your search for '.$query.' (Showing '.$data->num_results.' out of a possible '.$data->num_results.' matches)
'."\n";
echo '
'."\n";
foreach ($data->results as $item) {
//check to make sure short summary is available - set default message if it is not
if (strlen($item->summary_short) < 2) { $summary = 'Short summary not available.'; } else { $summary = $item->summary_short; }
if (strlen($item->mpaa_rating) < 2) { $rating = 'No rating available.'; } else { $rating = $item->mpaa_rating; }
echo '- '.$item->display_title.'
'.$summary.'
Opened on '.$item->publication_date.'.
Rated: '.$rating.' '."\n";
}
echo '
'."\n";
echo '
Reset the page
'."\n";
} else {
echo '
No results for '.$query.'.
'."\n";
echo '
Reset the page
'."\n";
}
?>