Skip to content

Instantly share code, notes, and snippets.

@piercemoore
Created July 13, 2012 16:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piercemoore/3105963 to your computer and use it in GitHub Desktop.
Save piercemoore/3105963 to your computer and use it in GitHub Desktop.
Quick Reddit reader in PHP
<?php
// Full disclosure: I wrote this while writing a Twitter Bootstrap enabled site, so the class tags are Twitter bootstrap enabled. Shouldn't be hard to style, though.
$subReddit = "webdev"; // Enter the subreddit name here with no /r/ in front
$selfTextLimit = 250; // Character limit for self text entries
$pageData = json_decode( file_get_contents( "http://www.reddit.com/r/$subReddit/.json" ) );
foreach( $pageData->data->children as $post ): ?>
<div class="well">
<h2>
<a href="<?=$post->data->permalink;?>" target="_blank"><?=$post->data->title;?></a>
<a href="<?=$post->data->url;?>" target="_blank" class="btn btn-primary btn-mini">
<i class="icon-share"></i> Link
</a>
</h2>
<p><?=substr( $post->data->selftext_html , 0 , $selfTextLimit );?></p>
<span class="label label-success"><i class="icon-chevron-up"></i> <?=$post->data->ups;?></span> |
<span class="label label-important"><i class="icon-chevron-down"></i> <?=$post->data->downs;?></span> |
<span class="label label-default"><?=$post->data->num_comments;?> comments</span>
</div>
<?php endforeach; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment