public
Last active

Quick Reddit reader in PHP

  • Download Gist
redditReaderBasic.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
<?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; ?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.