1) { print "argv > 1 \n"; $sub = $argv[1]; } $sub_url = 'https://www.reddit.com/r/' . $sub . '.json'; print 'searching for data from subreddit: ' . $sub_url . "\n"; $corgi_top_json = file_get_contents($sub_url); $corgi_top = json_decode($corgi_top_json, true)['data']['children']; foreach ($corgi_top as $post) { $image_url = $post['data']['url']; if (strpos($image_url, '.gif') === false && strpos($image_url, '.jpg') === false && strpos($image_url, '.jpeg') === false) { print "skipping " . $image_url . "\n"; continue; } $destination = getcwd() . "/corgis/" . basename($image_url); print "downloading to '$destination'\n"; file_put_contents($destination, file_get_contents($image_url)); }