Create a gist now

Instantly share code, notes, and snippets.

Quick Reddit reader in 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( "$subReddit/.json" ) );
foreach( $pageData->data->children as $post ): ?>
<div class="well">
<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
<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>
<?php endforeach; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment