user3437733
user3437733

Reputation: 1

JSON file_get_contents is not working small example included

Do you know why this doesn't work ?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="" content="">
</head>
<body>
<?php
$json_url="http://www.omdbapi.com/?t=titanic&y=1997";
$json = file_get_contents($json_url);
$info=json_decode($json);
print_r($info);
?>
</body>
</html>

The CodeLobster inspector will show all the php-lines but no error given, nothing happens. When running the code directly in IE or Firefox, no error msgs, nothing happens. PHP and Apache is up running, and other PHP-programs works fine. allow_url_fopen = On

This example is taken from http://99webtools.com/get-movie-info-imdb.php The example works OK when the clicking Sample Request

Kind Regards Torbjorn Ljung Sweden

Upvotes: 0

Views: 342

Answers (1)

Shijin TR
Shijin TR

Reputation: 7768

Use curl

$url="http://www.omdbapi.com/?t=titanic&y=1997";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
print_r(json_decode($result, true));

Upvotes: 1

Related Questions