mam skrypt zczytujacy rss lecz nie zczytuje mi daty wpisu nie wiem czemu. A jest mi ona potrzebna do sprawdzenia czy dany wpis jest juz w bazie danych czy tez nie.
pomocnicze funkcje
<?php require_once 'Entry.php'; class Channel { function __construct($url, $title, $desc) { $this->url = $url; $this->title = $title; $this->description = $desc; } public function getURL() { return $this->url; } public function getTitle() { return $this->title; } public function getDescription() { return $this->description; } public function addEntry(Entry $e) { $this->entries[] = $e; } public function getEntries() { return $this->entries; } private $url; private $title; private $description; } ?>
pomocnicze funkcje
<?php require_once 'Channel.php'; class Entry { public function __construct(Channel $c, $url, $title, $date, $desc) { $this->channel = $c; $this->url = $url; $this->title = $title; $this->date = $date; $this->description = $desc; } public function getChannel() { return $this->channel; } public function getURL() { return $this->url; } public function getTitle() { return $this->title; } return $this->date; } public function getDescription() { return $this->description; } private $channel; private $url; private $title; private $date; private $description; } ?>
wykonywalna czesc
<?php require_once 'Entry.php'; require_once 'Channel.php'; class Channels { $url = 'http://wiadomosci.wp.pl/kat,1342,ver,rss,rss.xml'; self::$urls[] = $url; } $mh = curl_multi_init(); $active = 0; foreach (self::$urls as $url) { $ch = curl_init($url); $chs[] = $ch; curl_setopt_array($ch, self::$options); curl_multi_add_handle($mh, $ch); } do { $result = curl_multi_exec($mh, $active); } while ($result == CURLM_CALL_MULTI_PERFORM); do { if (curl_multi_select($mh) != -1) { do { $result = curl_multi_exec($mh, $active); } while ($result == CURLM_CALL_MULTI_PERFORM); } } while ($active && $result == CURLM_OK); foreach ($chs as $ch) { if (curl_errno($ch) == 0) { $content = curl_multi_getcontent($ch); $channels[] = self::parseXML($content); } } return $channels; } $root = new SimpleXMLElement($xml); $url = $root->channel->link; $title = $root->channel->title; $description = $root->channel->description; $channel = new Channel($url, $title, $description); $b=1; foreach ($root->channel->item as $item) { $entryUrl = $item->link; $entryTitle = $item->title; $entryDescription = $item->description; /* $d1=addslashes($entryTitle); $d2=addslashes($entryDescription); if (last item w db == ) $blue = "INSERT INTO dane(name, title, dane) VALUES ('skicek', '$d1', '$d2')"; $ins = @mysql_query($blue); if($ins) echo $b." ok<br>"; else echo $b." Błąd nie udało się dodać nowego rekordu<br>"; */ $entry = new Entry($channel, $entryUrl, $entryTitle, $entryDate, $entryDescription); $channel->addEntry($entry); $b=$b+1; } return $channel; } CURLOPT_RETURNTRANSFER => true); } ?>
plik glowny
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl"> <head> <link href="style.css" rel="stylesheet" type="text/css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Czytnik RSS</title> </head> <body> <?php require_once 'Channel.php'; require_once 'Entry.php'; require_once 'Channels.php'; Channels::user('skicek'); $channels = Channels::get(); ?> <?php foreach ($channels as $channel): ?> <div class="channel"> <?php $entries = $channel->getEntries(); foreach ($entries as $entry) : ?> <div class="entry"> <p> </p> </div> <?php endforeach; ?> </div> <?php endforeach; ?> </body> </html>
wp dalem jako przykladowy xml.
ktos pomoże?