3

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
  • 2
    Can you post what you've tried so far? Jul 23, 2012 at 21:44

1 Answer 1

6
$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.

1
  • 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
    – Glen020
    Jul 24, 2012 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.