When I go to this link https://example.com/ch.php?content_id=1&stream_title=HD I get the content_stream of SD, I want to choose a specific stream_title (SD or HD or FHD)
Can anyone help me, please?
<?php
// The result of the request:
$json = <<<END_OF_STRING
{"live": [{"content_id": "1","title": "Channel 1","country_id": "2","language_id": "6","genre_id": "1","image_url": "","epg": {"daily": "","weekly": ""},"streams": {"live": [{"stream_title": "SD","content_stream": "http:\/\/example.com\/sd\/1","default": "0"}, {"stream_title": "HD","content_stream": "http:\/\/example.com\/hd\/1","default": "1"}, {"stream_title": "FHD","content_stream": "http:\/\/example.com\/fhd\/1","default": "0"}],"dvr": ""}}, {"content_id": "2","title": "Channel 2","country_id": "2","language_id": "6","genre_id": "2","image_url": "","epg": {"daily": "","weekly": ""},"streams": {"live": [{"stream_title": "SD","content_stream": "http:\/\/example.com\/sd\/2","default": "0"}, {"stream_title": "HD","content_stream": "http:\/\/example.com\/hd\/2","default": "1"}, {"stream_title": "FHD","content_stream": "http:\/\/example.com\/fhd\/2","default": "0"}],"dvr": ""}}]}
END_OF_STRING;
$json_decoded = json_decode($json);
$content_id = $_GET['content_id'];
$stream_title = $_GET['stream_title'];
$desiredLink = '';
for ($i = 0; $i < count($json_decoded->{'live'}); $i++) {
if ($content_id == $json_decoded->{'live'}[$i]->{'content_id'}) {
$desiredLink = $json_decoded->{'live'}[$i]->{'streams'}->{'live'}[$i]->{'content_stream'};
}
}
echo $desiredLink;