0

Hi tried to request each src value from wordpress media playlist , so i return data in JSON

My request Code which did not succeed was :

$decode_tracks = json_decode($track , true);

foreach ($decode_tracks[0][0] as $item) {
 print $item['src'];
}

This is some of the data that was returned.

[
      {
        "src": "http:\/\/localhost\/wordpress\/wp-content\/uploads\/2015\/08\/output.mkv",
        "type": "video\/x-matroska",
        "title": "output",
        "caption": "",
        "description": "",
        "meta": {
          "length_formatted": "0:16"
        }
      },
      {
        "src": "http:\/\/localhost\/wordpress\/wp-content\/uploads\/2015\/08\/christmas.mp4",
        "type": "video\/mp4",
        "title": "christmas",
        "caption": "tytj",
        "description": "tyjtyj",
        "meta": {
          "length_formatted": "1:21"
        }
      }
    ]
Yassine Qoraiche
  • 1,077
  • 14
  • 32

2 Answers2

1

Try this:

foreach ($decode_tracks as $item) {
     print $item['src'];
}

There is no need to convert json to array, you can easily do like this:

foreach ($track as $item) {
     print $item->src;
}
1
$decode_tracks = json_decode($track);

for ($i = 0; $i < count($decode_tracks); $i++) {
  print $decode_tracks[$i]->src;
}

Or if you are using array: try this one

$decode_tracks = json_decode($track, true);

for ($i = 0; $i < count($decode_tracks); $i++) {
  print $decode_tracks[$i]['src'];
}
0xdenishdev
  • 186
  • 4
  • 10