Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Working example of data by PHP JSON Object

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 90
    Comment on it

    Hello Reader's If you want to know more about the PHP JSON Object then this blog will helps you. Lets see how to handle the working data of it.

    <?php
    
    $trends_url = "http://search.twitter.com/trends/daily.json";
    
    // initialise the session
    $ch = curl_init();
    
    // Set the URL
    curl_setopt($ch, CURLOPT_URL, $trends_url);
    
    // Return the output from the cURL session rather than displaying in the browser.
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    //Execute the session, returning the results to $curlout, and close.
    $curlout = curl_exec($ch);
    curl_close($ch);
    
    $response = json_decode($curlout, true);
    
    foreach(array_keys($response['trends']) as $hours){
    print("<h3>".$hours."</h3>");
    for($c=0; $c < 20; $c++){
    print( ($c+1).". : ".$response['trends'][$hours][$c]['name']."<br />\n");
    }
    }
    // If you want to see the json_decode output just uncomment out the next 2 lines
    // $v = var_export($response);
    // echo $v;
    ?>
    

    Output:-

    stdClass Object
    (
        [trends] => Array
            (
                [0] => stdClass Object
                    (
                        [name] => Vote
                        [url] => http://search.twitter.com/search?q=Vote
                    )
    
                [1] => stdClass Object
                    (
                        [name] => Halloween
                        [url] => http://search.twitter.com/search?q=Halloween
                    )
    
                [2] => stdClass Object
                    (
                        [name] => Starbucks
                        [url] => http://search.twitter.com/search?q=Starbucks
                    )
    
                [3] => stdClass Object
                    (
                        [name] => #flylady
                        [url] => http://search.twitter.com/search?q=%23flylady
                    )
    
                [4] => stdClass Object
                    (
                        [name] => #votereport
                        [url] => http://search.twitter.com/search?q=%23votereport
                    )
    
                [5] => stdClass Object
                    (
                        [name] => Election Day
                        [url] => http://search.twitter.com/search?q=%22Election+Day%22
                    )
    
                [6] => stdClass Object
                    (
                        [name] => #PubCon
                        [url] => http://search.twitter.com/search?q=%23PubCon
                    )
    
                [7] => stdClass Object
                    (
                        [name] => #defrag08
                        [url] => http://search.twitter.com/search?q=%23defrag08
                    )
    
                [8] => stdClass Object
                    (
                        [name] => Melbourne Cup
                        [url] => http://search.twitter.com/search?q=%22Melbourne+Cup%22
                    )
    
                [9] => stdClass Object
                    (
                        [name] => Cheney
                        [url] => http://search.twitter.com/search?q=Cheney
                    )
    
            )
    
        [as_of] => Wed, 23 Dec 2015 21:49:36 +0000
    )
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: