Skip to content

Instantly share code, notes, and snippets.

@ryaan-anthony
Created May 31, 2015 14:31
Show Gist options
  • Select an option

  • Save ryaan-anthony/a9ca9aafb5374ec0e22a to your computer and use it in GitHub Desktop.

Select an option

Save ryaan-anthony/a9ca9aafb5374ec0e22a to your computer and use it in GitHub Desktop.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.reddit.com/r/philadelphia/.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
if($output = json_decode($output)){
$children = $output->data->children;
foreach($children as $child){
// if post is a question (contains a "?" character)
if(stristr($child->data->title, "?") !== false){
echo "(" . $child->data->id . ") " . $child->data->title . (php_sapi_name() == "cli" ? PHP_EOL : "<br>");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment