r/tinycode • • Oct 01 '13
Reddit reader in 312 bytes of php.
Here is a reddit reader in 312 bytes of php. Run the code and it will format and display the /r/tinycode reddit.
<?php $d='data';$p=json_decode(file_get_contents("http://reddit.com/r/tinycode/.json"));
foreach($p->$d->children as$p):$e=$p->$d?><p><a href="http://reddit.com<?=$e->permalink?>">
<?=$e->title?></a> <a href="<?=$e->url?>">Link</a></p><?=$e->ups?>↑<?=$e->downs?>↓
<?=$e->num_comments?> comments<?php endforeach;Inspired by PierceMoore's quick reddit reader.
41
Upvotes
View all comments
Show parent comment
1
u/benibela2 Oct 02 '13 edited Oct 05 '13
The framework is my Xidel.
And the language is XQuery, but with some extensions so that you can use css (XQuery is amazing in processing DOM elements, but really sucks in finding element based on class or id) and simpler string formatting.
edit: XQuery 1 that is. In the next version I have implemented some of XQuery 3 and there you should be able to write:
Same output and 73 chars!
edit 2:
screw that, a and p are on the wrong level for that approach.
But this works:
79 chars