1: <?php
2: 3: 4: 5:
6:
7:
8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29:
30:
31: function RSS_Tags($item, $type) {
32: $y = array();
33: $y["type"] = $type;
34: $tnl = $item->getElementsByTagName("title");
35: $tnl = $tnl->item(0);
36: if (is_object($tnl->firstChild)) {
37: $y["title"] = $tnl->firstChild->textContent;
38: } else {
39: $y["title"] = '';
40: }
41:
42: $tnl = $item->getElementsByTagName("link");
43: $tnl = $tnl->item(0);
44: if (is_object($tnl->firstChild)) {
45: $link = $tnl->firstChild->textContent;
46: $y["link"] = $link;
47: } else {
48: $y["link"] = '';
49: }
50:
51: $tnl = $item->getElementsByTagName("description");
52: $tnl = $tnl->item(0);
53: if (is_object($tnl->firstChild)) {
54: $y["description"] = $tnl->firstChild->textContent;
55: } else {
56: $y["description"] = '';
57: }
58:
59: $tnl = $item->getElementsByTagName("pubDate");
60: $tnl = $tnl->item(0);
61: if (is_object($tnl->firstChild)) {
62: $y["pubDate"] = $tnl->firstChild->textContent;
63: } else {
64: $y["pubDate"] = '';
65: }
66: return $y;
67: }
68:
69: function RSS_Channel($channel) {
70: $RSS_Content = array();
71: $items = $channel->getElementsByTagName("item");
72:
73: $y = RSS_Tags($channel, 0);
74: array_push($RSS_Content, $y);
75:
76: foreach($items as $item) {
77: $y = RSS_Tags($item, 1);
78: array_push($RSS_Content, $y);
79: }
80: return $RSS_Content;
81: }
82:
83: function RSS_Retrieve($url) {
84: $RSS_Content = array();
85: $doc = new DOMDocument();
86: if (@$doc->load($url)) {
87: $channels = $doc->getElementsByTagName("channel");
88: foreach($channels as $channel) {
89: $RSS_Content = array_merge($RSS_Content, RSS_Channel($channel));
90: }
91: return $RSS_Content;
92: } else {
93: return NULL;
94: }
95: }
96:
97: ?>
98: