Muhmd Diab
Muhmd Diab

Reputation: 29

I want to Echo IMDB ID, Title, Quality and Embed URL From This JSON URL

Now I have this JSON URL https://vidsrc.me/movies/latest/page-1.json I want to echo IMDB ID, Title, Quality and Embed URL for each array as this sounds like a multidimensional array. But every time I try to do this. I get one of the following errors: - Undefined Index - Undefined offset So I want to loop through it and echo each of those items and break line between each, This is the code

<?php
$url = file_get_contents('https://vidsrc.me/movies/latest/page-1.json');
$decode = json_decode($url, TRUE);
$res = $decode->result;
foreach($decode as $value){
    $imdb    = $res->imdb_id;
    $title   = $res->title;
    $quality = $res->quality;
    $url     = $res->embed_url;
    echo $imdb;
    echo "<br>";
    echo $tite;
    echo "<br>";
    echo $quality;
    echo "<br>";
    echo $url;
}
?>

Upvotes: 3

Views: 480

Answers (1)

MorganFreeFarm
MorganFreeFarm

Reputation: 3733

json_decode() returns you array but you process it like object, you should process it as array:

<?php
$url = file_get_contents('https://vidsrc.me/movies/latest/page-1.json');
$decode = json_decode($url, TRUE);
foreach($decode['result'] as $value){
    $imdb    = $value['imdb_id'];
    $title   = $value['title'];
    $quality = $value['quality'];
    $url     = $value['embed_url'];
    echo $imdb;
    echo "<br>";
    echo $title;
    echo "<br>";
    echo $quality;
    echo "<br>";
    echo $url;
}
?>

Upvotes: 1

Related Questions