Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

SChaput

macrumors regular
Original poster
Jul 2, 2008
153
0
United States
Goodmorning,

I'm trying to parse some information using twitters API. It returns a JSON array that looks like this:

Code:
Array
(
    [0] => stdClass Object
        (
            [created_at] => 2012-02-12T15:27:55Z
            [as_of] => 2012-02-12T15:28:25Z
            [locations] => Array
                (
                    [0] => stdClass Object
                        (
                            [name] => Worldwide
                            [woeid] => 1
                        )

                )

            [trends] => Array
                (
                    [0] => stdClass Object
                        (
                            [query] => %22R.I.P%20Whitney%20Houston%22
                            [name] => R.I.P Whitney Houston
                            [promoted_content] => 
                            [url] => http://twitter.com/search/%22R.I.P%20Whitney%20Houston%22
                            [events] => 
                        )

                    [1] => stdClass Object
                        (
                            [query] => %231DHQLouis
                            [name] => #1DHQLouis
                            [promoted_content] => 
                            [url] => http://twitter.com/search/%231DHQLouis
                            [events] => 
                        )

                    [2] => stdClass Object
                        (
                            [query] => %23thingsthatpissmeoffingeneral
                            [name] => #thingsthatpissmeoffingeneral
                            [promoted_content] => 
                            [url] => http://twitter.com/search/%23thingsthatpissmeoffingeneral
                            [events] => 
                        )

                    [3] => stdClass Object
                        (
                            [query] => %22The%20Greatest%20Love%22
                            [name] => The Greatest Love
                            [url] => http://twitter.com/search/%22The%20Greatest%20Love%22
                            [promoted_content] => 
                            [events] => 
                        )

                    [4] => stdClass Object
                        (
                            [query] => %23IMFROM
                            [name] => #IMFROM
                            [promoted_content] => 
                            [url] => http://twitter.com/search/%23IMFROM
                            [events] => 
                        )

                    [5] => stdClass Object
                        (
                            [query] => %22Kristen%20Does%20Smile%22
                            [name] => Kristen Does Smile
                            [promoted_content] => 
                            [url] => http://twitter.com/search/%22Kristen%20Does%20Smile%22
                            [events] => 
                        )

                    [6] => stdClass Object
                        (
                            [query] => %22Ra%C3%A7a%20Negra%22
                            [name] => Raça Negra
                            [url] => http://twitter.com/search/%22Ra%C3%A7a%20Negra%22
                            [promoted_content] => 
                            [events] => 
                        )

                    [7] => stdClass Object
                        (
                            [query] => %22Saving%20All%20My%20Love%20For%20You%22
                            [name] => Saving All My Love For You
                            [promoted_content] => 
                            [url] => http://twitter.com/search/%22Saving%20All%20My%20Love%20For%20You%22
                            [events] => 
                        )

                    [8] => stdClass Object
                        (
                            [query] => %22You%20Give%20Good%20Love%22
                            [name] => You Give Good Love
                            [promoted_content] => 
                            [url] => http://twitter.com/search/%22You%20Give%20Good%20Love%22
                            [events] => 
                        )

                    [9] => stdClass Object
                        (
                            [promoted_content] => 
                            [query] => %22Feyenoord%20-%20Vitesse%22
                            [name] => Feyenoord - Vitesse
                            [url] => http://twitter.com/search/%22Feyenoord%20-%20Vitesse%22
                            [events] => 
                        )

                )

        )

)
I'm getting this using the following code:
Code:
header("Content-Type: text/plain");
$page = json_decode(file_get_contents("https://api.twitter.com/1/trends/1.json"));
print_r($page);
How can I cycle through the 'TREND' array. I tried echo $page['trends][0]['name']; to get one value but it returns nothing.

Any advice is appreciated!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.