How to call the JSON URL in php which includes spaces in query -
when making xml request tmdb.org using this
$movie_name="dabangg 2"; $xml = simplexml_load_file("http://api.themoviedb.org/2.1/movie.search/en/xml/accd3ddbbae37c0315fb5c8e19b815a5/"$movie_name"");
and working !!
now have change url since response json not xml
i have changed
<?php $movie_name="dabangg 2"; $url="http://api.themoviedb.org/3/search/movie?api_key=accd3ddbbae37c0315fb5c8e19b815a5&query=$movie_name"; $json = file_get_contents($url); var_dump($json); ?>
but not work
if search
http://api.themoviedb.org/3/search/movie?api_key=accd3ddbbae37c0315fb5c8e19b815a5&query=dabangg 2
on browser results.
warning: file_get_contents(http://api.themoviedb.org/3/search/movie?api_key=accd3ddbbae37c0315fb5c8e19b815a5&query=dabangg 2) [function.file-get-contents]: failed open stream: http request failed! http/1.1 400 bad_request in /home/wwww/public_html/test/movie.php on line3
please me
look on : http://codular.com/curl-with-php
try below code :
<?php $movie_name="dabangg 2"; $movie_name = urlencode($movie_name); $url="http://api.themoviedb.org/3/search/movie?api_key=accd3ddbbae37c0315fb5c8e19b815a5&query=$movie_name"; // curl resource $curl = curl_init(); // set options - passing in useragent here curl_setopt_array($curl, array( curlopt_returntransfer => 1, curlopt_url => $url, curlopt_useragent => 'codular sample curl request' )); // send request & save response $resp $resp = curl_exec($curl); // close request clear resources curl_close($curl); var_dump($resp); ?>
Comments
Post a Comment