PHP Warning : file_get_contents failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request

json, php

Solution

try `urlencode()`:

 $film_q   = urlencode($film_name[0]->title);
 $imdb_uri = "http://www.imdbapi.com/?i=&t=$film_q";

Problem

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?

Original source