Externe rss lezen
http://feeds.feedburner.com/tweakers/, maar van http://www.rtl.nl/service/rss/rtlnieuws/index.xml lukt dat dan weer niet. Heeft iemand hier een verklaring voor??
( Ik probeerde file_get_contents()/SimpleXmlElement en simplexml_load_file() )
Ik heb een vraagje, ik kan namelijk gewoon die RSS Feeds uitlezen van ( Ik probeerde file_get_contents()/SimpleXmlElement en simplexml_load_file() )
Om in db te zetten.?
kzalt efkes zoeken en dan posten in deze post
EDIT:
Hier is het script:
je moet de db gegevens wel eventjes aanpassen,
je kan het ook echo'en zoals je wilt enzo...
hf with it
Edit2:
:o Ik bekijk just die .xml, kan zijn dat ge nog wat gaat mogen aanpassen op de atributen waarop hij moet zoeken enzo
Code (php)
1
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
include("./config/connect.php");
mysql_select_db("dbnaam") or die("Could not select db");
$RSS_Content = array();
function RSS_Tags($item, $type)
{
$y = array();
$tnl = $item->getElementsByTagName("title");
$tnl = $tnl->item(0);
$title = $tnl->firstChild->data;
$tnl = $item->getElementsByTagName("link");
$tnl = $tnl->item(0);
$link = $tnl->firstChild->data;
$tnl = $item->getElementsByTagName("description");
$tnl = $tnl->item(0);
$description = $tnl->firstChild->data;
$tnl = $item->getElementsByTagName("pubDate");
$tnl = $tnl->item(0);
$pubDate = $tnl->firstChild->data;
$y["title"] = $title;
$y["link"] = $link;
$y["description"] = $description;
$y["pubDate"] = $pubDate;
return $y;
}
function RSS_Channel($channel)
{
global $RSS_Content;
$items = $channel->getElementsByTagName("item");
// Processing channel
$y = RSS_Tags($channel, 0); // get description of channel, type 0
array_push($RSS_Content, $y);
// Processing articles
foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}
}
function RSS_Retrieve($url)
{
global $RSS_Content;
$doc = new DOMDocument();
$doc->load($url);
$channels = $doc->getElementsByTagName("channel");
$RSS_Content = array();
foreach($channels as $channel)
{
RSS_Channel($channel);
}
}
function RSS_RetrieveLinks($url)
{
global $RSS_Content;
$doc = new DOMDocument();
$doc->load($url);
$channels = $doc->getElementsByTagName("channel");
$RSS_Content = array();
foreach($channels as $channel)
{
$items = $channel->getElementsByTagName("item");
foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}
}
}
function RSS_Links($url, $size)
{
global $RSS_Content;
$page = "<ul>";
RSS_RetrieveLinks($url);
if($size > 0)
$recents = array_slice($RSS_Content, 0, $size);
foreach($recents as $article)
{
$type = $article["type"];
if($type == 0) continue;
$title = $article["title"];
$link = $article["link"];
$page .= "<li><a href=\"$link\">$title</a></li>\n";
}
$page .="</ul>\n";
return $page;
}
function RSS_Display($url, $size)
{
global $RSS_Content;
$opened = false;
$page = "";
RSS_Retrieve($url);
if($size > 0)
$recents = array_slice($RSS_Content, 0, $size);
foreach($recents as $article)
{
$type = $article["type"];
if($type == 0)
{
if($opened == true)
{
$page .="</ul>\n";
$opened = false;
}
$page .="<b>";
}
else
{
if($opened == false)
{
$page .= "<ul>\n";
$opened = true;
}
}
$title = $article["title"];
$link = $article["link"];
$description = $article["description"];
$pubDate = $article["pubDate"];
$date = date("Y-m-d");
$weergeven = "2";
$posted = "krant";
mysql_query("INSERT INTO `nieuws` (`id`,`title`,`posted`,`link`,`description`,`pubDate`,`date`,`weergeven`) VALUES ('','".$title."','".$posted."','".$link."','".$description."','".$pubDate."','".$date."','".$weergeven."')");
$page .= "<li><a href=\"$link\">$title</a>";
if($description != false)
{
$page .= "<br>$description";
}
$page .= "</li>\n";
if($type==0)
{
$page .="</b><br />";
}
}
if($opened == true)
{
$page .="</ul>\n";
}
}
?>
include("./config/connect.php");
mysql_select_db("dbnaam") or die("Could not select db");
$RSS_Content = array();
function RSS_Tags($item, $type)
{
$y = array();
$tnl = $item->getElementsByTagName("title");
$tnl = $tnl->item(0);
$title = $tnl->firstChild->data;
$tnl = $item->getElementsByTagName("link");
$tnl = $tnl->item(0);
$link = $tnl->firstChild->data;
$tnl = $item->getElementsByTagName("description");
$tnl = $tnl->item(0);
$description = $tnl->firstChild->data;
$tnl = $item->getElementsByTagName("pubDate");
$tnl = $tnl->item(0);
$pubDate = $tnl->firstChild->data;
$y["title"] = $title;
$y["link"] = $link;
$y["description"] = $description;
$y["pubDate"] = $pubDate;
return $y;
}
function RSS_Channel($channel)
{
global $RSS_Content;
$items = $channel->getElementsByTagName("item");
// Processing channel
$y = RSS_Tags($channel, 0); // get description of channel, type 0
array_push($RSS_Content, $y);
// Processing articles
foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}
}
function RSS_Retrieve($url)
{
global $RSS_Content;
$doc = new DOMDocument();
$doc->load($url);
$channels = $doc->getElementsByTagName("channel");
$RSS_Content = array();
foreach($channels as $channel)
{
RSS_Channel($channel);
}
}
function RSS_RetrieveLinks($url)
{
global $RSS_Content;
$doc = new DOMDocument();
$doc->load($url);
$channels = $doc->getElementsByTagName("channel");
$RSS_Content = array();
foreach($channels as $channel)
{
$items = $channel->getElementsByTagName("item");
foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}
}
}
function RSS_Links($url, $size)
{
global $RSS_Content;
$page = "<ul>";
RSS_RetrieveLinks($url);
if($size > 0)
$recents = array_slice($RSS_Content, 0, $size);
foreach($recents as $article)
{
$type = $article["type"];
if($type == 0) continue;
$title = $article["title"];
$link = $article["link"];
$page .= "<li><a href=\"$link\">$title</a></li>\n";
}
$page .="</ul>\n";
return $page;
}
function RSS_Display($url, $size)
{
global $RSS_Content;
$opened = false;
$page = "";
RSS_Retrieve($url);
if($size > 0)
$recents = array_slice($RSS_Content, 0, $size);
foreach($recents as $article)
{
$type = $article["type"];
if($type == 0)
{
if($opened == true)
{
$page .="</ul>\n";
$opened = false;
}
$page .="<b>";
}
else
{
if($opened == false)
{
$page .= "<ul>\n";
$opened = true;
}
}
$title = $article["title"];
$link = $article["link"];
$description = $article["description"];
$pubDate = $article["pubDate"];
$date = date("Y-m-d");
$weergeven = "2";
$posted = "krant";
mysql_query("INSERT INTO `nieuws` (`id`,`title`,`posted`,`link`,`description`,`pubDate`,`date`,`weergeven`) VALUES ('','".$title."','".$posted."','".$link."','".$description."','".$pubDate."','".$date."','".$weergeven."')");
$page .= "<li><a href=\"$link\">$title</a>";
if($description != false)
{
$page .= "<br>$description";
}
$page .= "</li>\n";
if($type==0)
{
$page .="</b><br />";
}
}
if($opened == true)
{
$page .="</ul>\n";
}
}
?>
Gewijzigd op 01/01/1970 01:00:00 door Matthias R
Die van tweakers werkt prima, maar die van rtl.nl of nu.nl werkt niet.
Code (php)
1
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
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
<?php
printFeeds('http://feeds.feedburner.com/tweakers/');
//printFeeds('http://www.rtl.nl/service/rss/rtlnieuws/index.xml');
function printFeeds($url)
{
$doc = new DOMDocument();
$doc->load($url);
$channels = $doc->getElementsByTagName("channel");
$RSS_Content = array();
foreach($channels as $channel)
{
$items = $channel->getElementsByTagName("item");
foreach($items as $item)
{
$y = array();
$tnl = $item->getElementsByTagName("title");
$tnl = $tnl->item(0);
$title = $tnl->firstChild->data;
echo $title . "<br>";
}
}
}
?>
printFeeds('http://feeds.feedburner.com/tweakers/');
//printFeeds('http://www.rtl.nl/service/rss/rtlnieuws/index.xml');
function printFeeds($url)
{
$doc = new DOMDocument();
$doc->load($url);
$channels = $doc->getElementsByTagName("channel");
$RSS_Content = array();
foreach($channels as $channel)
{
$items = $channel->getElementsByTagName("item");
foreach($items as $item)
{
$y = array();
$tnl = $item->getElementsByTagName("title");
$tnl = $tnl->item(0);
$title = $tnl->firstChild->data;
echo $title . "<br>";
}
}
}
?>
Warning: DOMDocument::load(http://www.rtl.nl/service/rss/rtlnieuws/index.xml) [function.DOMDocument-load]: failed to open stream: Connection refused in * on line 9
Warning: DOMDocument::load() [function.DOMDocument-load]: I/O warning : failed to load external entity "http://www.rtl.nl/service/rss/rtlnieuws/index.xml" in * on line 9
Gewijzigd op 01/01/1970 01:00:00 door krijn
dit script kunnen proberen.
Je zou