asimryu

naver.php for rss read

Jun 27th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.59 KB | None | 0 0
  1. <?php
  2. $sch = "";
  3. if( isset($_GET['sch']) ) $sch = $_GET['sch'];
  4. $news = "http://newssearch.naver.com/search.naver?where=rss&query={$sch}&field=0&nx_search_query=&nx_and_query=&nx_sub_query=&nx_search_hlquery=";
  5. $xml = simplexml_load_file($news);
  6. //var_dump($xml);
  7. $channel = $xml->channel;
  8. $newslist = $channel->item;
  9. $data = array();
  10. $no = 0;
  11. foreach( $newslist as $news ){
  12.     $data[$no] = array(
  13.         'title'=> $news->title,
  14.         'author'=>$news->author,
  15.         'link'=>$news->link,
  16.         'category' => $news->category,
  17.         'pubDate' => $news->pubDate
  18.     );
  19.     $no++;
  20. }
  21. $json = json_encode($data);
  22. echo $json;
Advertisement
Add Comment
Please, Sign In to add comment