Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.