Zabkas
Zabkas

Reputation: 67

How to get json output in php from url

I see there is some more questions about this, but not useful for me.

Here i have the link and following code i am Link

<?php 
$json=file_get_contents("http://2strok.com/radio.json");
$details=json_decode($json);
if($details->Response=='True')
?>

<?php echo $details->name[3];?><br>

Upvotes: 1

Views: 71

Answers (2)

Panos Kalatzantonakis
Panos Kalatzantonakis

Reputation: 12683

$json=file_get_contents("http://2strok.com/radio.json");
$details=json_decode($json,true);
foreach($details as $output) {
    echo $output['name'].'<br>';
}

Update - get specific name

$json=file_get_contents("http://2strok.com/radio.json");
$details=json_decode($json,true);
foreach($details as $output) {
    if ($output['name']=='FM 101 / Islamabad'){
        echo 'Specific name found: '.$output['name'];
    }
    // echo $output['name'].'<br>';
}

Upvotes: 3

Phil
Phil

Reputation: 1464

After json decode, it returns an array of objects, so try this:

$json=file_get_contents("http://2strok.com/radio.json");
$details=json_decode($json);

foreach ($details as $detail){
    echo $detail->name;
    echo "<br>";
} 
?>

Upvotes: 1

Related Questions