Advertisement
Guest User

rss2json.com api php example

a guest
Feb 27th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. <?php
  2.     $rss_url = 'https://news.ycombinator.com/rss';
  3.    
  4.     $api_endpoint = 'https://api.rss2json.com/v1/api.json';
  5.  
  6.     $api_key = '00000000000000000000000000000000000000000';
  7.  
  8.  
  9.  
  10.    
  11.     $params = http_build_query(array(
  12.         'rss_url'=>$rss_url,
  13.         'api_key'=>$api_key,
  14.         'count'=>5
  15.  
  16.     ));
  17.  
  18.     $data = json_decode( file_get_contents($api_endpoint . '?' . $params ) , true );
  19.  
  20.     if($data['status'] == 'ok'){
  21.         echo "====== {$data['feed']['title']} ======\n";
  22.  
  23.         foreach ($data['items'] as $item) {
  24.             echo "{$item['title']}\n";
  25.         }
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement