Just wondering if someone has sample code to return the top 25 links of reddit (using PHP). In JSON or XML. i can't wrap my head around the API... and rarely use python.
1 Answer
$array = (array) json_decode(file_get_contents("http://www.reddit.com/.json"));
That will return a PHP array with all the data from the front page. You can limit how many you display using a simple while() loop.
This is very simple now that you have the array from above, because all you have to do is step through it.
-
This works thank you. Just having troubles digging into such deep arrays in php. For example the first title is here. Array ( [0] => stdClass Object ( [kind] => t3 [data] => stdClass Object ( [domain] => imgur.com [banned_by] => [media_embed] => stdClass Object ( ) [subreddit] => funny [selftext_html] => [selftext] => [likes] => [link_flair_text] => [id] => x2gx8 [clicked] => [title] => What are you doing? any quick tips to get it? Thanks– Glen020Jul 24, 2012 at 15:22