Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

json

foreach

php

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;
}
?>
like image 840
Muhmd Diab Avatar asked Nov 19 '25 11:11

Muhmd Diab


1 Answers

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;
}
?>
like image 186
MorganFreeFarm Avatar answered Nov 22 '25 03:11

MorganFreeFarm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!