Advertisement
joris

File Get Content

Aug 15th, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.60 KB | None | 0 0
  1. <?php
  2. include "koneksi2.php";
  3. /**
  4. *$Author: youngbobby $
  5. *$Website: http://youngbobby.com
  6. *$Date: 2011-04-23 13:05 +0100 $
  7. *
  8. *Use the code to read data from an external RSS site.
  9. *Please use a VALID URL too.
  10. *
  11. *FEEL FREE TO MODIFY.
  12. */
  13.  
  14.  //The URL to get the Feeds Data from:
  15.  
  16. $data    = file_get_contents("http://rss.vivanews.com/get/all/");
  17. $doc = new SimpleXmlElement($data, LIBXML_NOCDATA);
  18.  
  19.       echo '<div style="padding:4px;">';
  20.  
  21. if(isset($doc->channel))
  22. {
  23.     parseRSS($doc);
  24. }
  25. if(isset($doc->entry))
  26. {
  27.     parseAtom($doc);
  28. }
  29.     echo "</div>";
  30.  
  31. function parseRSS($xml)
  32. {
  33.     echo "<strong>".$xml->channel->title."</strong>
  34.    <br />";
  35.     $cnt = count($xml->channel->item);
  36.  
  37.     for($i=0; $i<$cnt; $i++)
  38.     {
  39.         $item_url    = $xml->channel->item[$i]->link;
  40.     $item_cat    = $xml->channel->item[$i]->category;
  41.         $item_title  = $xml->channel->item[$i]->title;
  42.         $item_desc   = $xml->channel->item[$i]->description;
  43.     $feed_url    = "http://rss.vivanews.com/get/all/";
  44.     $item_date   = $xml->channel->item[$i]->pubDate;
  45.     $fetch_date  = date("Y-m-j G:i:s");
  46.     $RemoveImageTag = preg_replace("/<img[^>]+\>/i", "", $item_desc);
  47.     $Hajar = strip_tags($RemoveImageTag);
  48.     $Tanggal = date("Y/m/d");
  49.  
  50.  $result = mysql_query("SELECT item_url FROM vivanews where item_url='$item_url'");
  51.  $ketemu = mysql_num_rows($result);
  52.  $data = mysql_fetch_array ($result);
  53.  
  54.     if ($ketemu == 0){
  55.        $simpan = "insert into vivanews (feed_url, item_title, item_date, item_url, fetch_date, item_desc, item_cat) values ('$feed_url','$item_title','$Tanggal','$item_url','$fetch_date','$Hajar','$item_cat')";
  56.            $exc=mysql_query($simpan);
  57.     }
  58.  
  59.  
  60.     echo '<table><tr><td><b><a target="_blank" href="'.$item_url.'">'.$item_title.'</a></b></td></tr> <tr><td>'.$item_desc.'<br /><br /></td></tr> <tr><td>'.$item_date.'<br /><br /></td></tr> <tr><td>'.$item_cat.'<br /><br /></td></tr></table>';
  61.  
  62.         if ($i == 30) {
  63.             break;
  64.         }
  65.     }
  66. }
  67.  
  68. function parseAtom($xml)
  69. {
  70.     echo "<strong>".$xml->author->name."</strong>";
  71.     $cnt = count($xml->entry);
  72.     for($i=0; $i<$cnt; $i++)
  73.     {
  74.     $urlAtt           = $xml->entry->link[$i]->attributes();
  75.     $feed_url         = $xml->entry->feed_url;
  76.     $item_date        = $xml->entry->item_date;
  77.     $item_url         = $xml->entry->item_url;
  78.     $item_title       = $xml->entry->title;
  79.     $item_desc        = $xml->entry->item_desc;
  80.     $fetch_date       = $xml->entry->fetch_date;
  81.     $item_cat         = $xml->entry->item_cat;
  82.  
  83.     echo '<a href="'.$item_url.'">'.$item_title.'</a>'.$item_desc.'';
  84.     }
  85. }
  86.  
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement