0

I want to get the episode number and Released from
http://www.omdbapi.com/?t=the+walking+dead&season=6&r=json
but I don't know how to extract arrays from the api.

Can someone help me?

My code is:

$title = 'the+walking+dead';
$title2 = urlencode($title);
$json=file_get_contents("http://www.omdbapi.com/?t=$title2&season=6&r=json");
$details=json_decode($json);
if($details->Response=='True')
{   
        $episodios=$details->Episodes;
}
1
  • Add the language tag. Commented Nov 4, 2015 at 12:34

2 Answers 2

3
$title = 'the+walking+dead';
$title2 = urlencode($title);
$json = file_get_contents("http://www.omdbapi.com/?t=$title2&season=6&r=json");
$details = json_decode($json);
if ($details->Response == 'True') {

    echo 'There are ' . count($details->Episodes) . ' episodes<br />';

    foreach ($details->Episodes as $key => $episode) {
        echo 'Episode criteria number is ' . ($key + 1) . '<br />';
        echo 'Episode Number: ' . $episode->Episode . '<br />';
        echo 'Released: ' . $episode->Released . '<br />';
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you and who i count the episodes of the season? To get the total?
if ($details->Response == 'True') { $i = 0; foreach ($details->Episodes as $episode) { $i++; echo 'Episode Number: ' . $episode->Episode . '<br />'; echo 'Released: ' . $episode->Released . '<br />'; } echo $i; }
Just add a counter variable (such as $i), and in each iteration, add 1 to it, probably Matei will update answer with full code
@AdolfoRodrigues I've just updated my answer.. to count the episodes you simply use the count() function
0
<?php

$title = 'the+walking+dead';
$title2 = urlencode($title);
$json=file_get_contents("http://www.omdbapi.com/t=$title2&season=6&r=json");
$details=json_decode($json);
if($details->Response=='True')
{   
    $episodios=$details->Episodes;
    foreach ($episodios as $episode) {
        echo 'Episode Number: ' . $episode->Episode . '<br />';
        echo 'Released Date: ' . $episode->Released . '<br />';
    }
}
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.