I have built a local DVD Database using Codeigniter, With film names etc in. What I am looking to do is load in more data for the film from this IMDB API.
However I am getting the following error :
A PHP Error was encountered
Severity: Warning
Message: file_get_contents(http://www.imdbapi.com/?i=&t=2 Fast 2 Furious) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
Filename: controllers/dvd.php
Line Number: 92
Copying this URI into an address bar returns the json data, But when loading in my page it gives me that error.
It is worth noting I am running on a localhost this particular site. As I am just familiarising myself with Codeigniter.
My code is....
// Send Query To IMDB Api
$film_q = $film_name[0]->title;
$imdb_uri = "http://www.imdbapi.com/?i=&t=$film_q";
$json = file_get_contents($imdb_uri);
$json = json_decode($json);
print_r($json);
EDIT : Looking further into this. Single word film names seem to load in ok, So I'm assuming I need to someway drill down a "+" into the spaces?
try urlencode()
:
$film_q = urlencode($film_name[0]->title);
$imdb_uri = "http://www.imdbapi.com/?i=&t=$film_q";
You might consider running urlencode() on the movie title. It's possible that the spaces in "2 Fast 2 Furious" were left behind.
Your link should look like this.
http://www.imdbapi.com/?i=&t=2%20Fast%202%20Furious
Not this.
http://www.imdbapi.com/?i=&t=2 Fast 2 Furious
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With