Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include "koneksi2.php";
- /**
- *$Author: youngbobby $
- *$Website: http://youngbobby.com
- *$Date: 2011-04-23 13:05 +0100 $
- *
- *Use the code to read data from an external RSS site.
- *Please use a VALID URL too.
- *
- *FEEL FREE TO MODIFY.
- */
- //The URL to get the Feeds Data from:
- $data = file_get_contents("http://rss.vivanews.com/get/all/");
- $doc = new SimpleXmlElement($data, LIBXML_NOCDATA);
- echo '<div style="padding:4px;">';
- if(isset($doc->channel))
- {
- parseRSS($doc);
- }
- if(isset($doc->entry))
- {
- parseAtom($doc);
- }
- echo "</div>";
- function parseRSS($xml)
- {
- echo "<strong>".$xml->channel->title."</strong>
- <br />";
- $cnt = count($xml->channel->item);
- for($i=0; $i<$cnt; $i++)
- {
- $item_url = $xml->channel->item[$i]->link;
- $item_cat = $xml->channel->item[$i]->category;
- $item_title = $xml->channel->item[$i]->title;
- $item_desc = $xml->channel->item[$i]->description;
- $feed_url = "http://rss.vivanews.com/get/all/";
- $item_date = $xml->channel->item[$i]->pubDate;
- $fetch_date = date("Y-m-j G:i:s");
- $RemoveImageTag = preg_replace("/<img[^>]+\>/i", "", $item_desc);
- $Hajar = strip_tags($RemoveImageTag);
- $Tanggal = date("Y/m/d");
- $result = mysql_query("SELECT item_url FROM vivanews where item_url='$item_url'");
- $ketemu = mysql_num_rows($result);
- $data = mysql_fetch_array ($result);
- if ($ketemu == 0){
- $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')";
- $exc=mysql_query($simpan);
- }
- 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>';
- if ($i == 30) {
- break;
- }
- }
- }
- function parseAtom($xml)
- {
- echo "<strong>".$xml->author->name."</strong>";
- $cnt = count($xml->entry);
- for($i=0; $i<$cnt; $i++)
- {
- $urlAtt = $xml->entry->link[$i]->attributes();
- $feed_url = $xml->entry->feed_url;
- $item_date = $xml->entry->item_date;
- $item_url = $xml->entry->item_url;
- $item_title = $xml->entry->title;
- $item_desc = $xml->entry->item_desc;
- $fetch_date = $xml->entry->fetch_date;
- $item_cat = $xml->entry->item_cat;
- echo '<a href="'.$item_url.'">'.$item_title.'</a>'.$item_desc.'';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement