質問編集履歴
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -29,3 +29,395 @@
|
|
29
29
|
|
30
30
|
|
31
31
|
自分はphpに関してはほとんど知識がないので、そっち重点的に教えていただけると助かります。
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
追記
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
リンク貼ってあったURLを自分なりに編集してみましたが、エラーは吐かなかったものの、SiteTitleタグ内には何も入りませんでした。
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
<?php
|
46
|
+
|
47
|
+
header("Content-Type: text/html; charset=UTF-8");
|
48
|
+
|
49
|
+
//XML上部分作成
|
50
|
+
|
51
|
+
$rssHeader = <<<RSS
|
52
|
+
|
53
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
54
|
+
|
55
|
+
<rss version="2.0">
|
56
|
+
|
57
|
+
<channel>
|
58
|
+
|
59
|
+
<title>サイトタイトル</title>
|
60
|
+
|
61
|
+
<description>サイト概要</description>
|
62
|
+
|
63
|
+
<link>サイトURL</link>
|
64
|
+
|
65
|
+
<author>管理人</author>
|
66
|
+
|
67
|
+
<pubDate>日付</pubDate>
|
68
|
+
|
69
|
+
<language>ja</language>
|
70
|
+
|
71
|
+
RSS;
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
//フィード登録(例:サッカー関連2chまとめのRSSフィード)
|
76
|
+
|
77
|
+
$data['feedurl'][] = 'http://alfalfalfa.com/index.rdf';
|
78
|
+
|
79
|
+
$data['feedurl'][] = 'http://news.2chblog.jp/index.rdf';
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
$rssList = $data['feedurl'];
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
//同時呼び出し
|
88
|
+
|
89
|
+
$rssdataRaw = multiRequest($rssList);
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
$count = '0';
|
94
|
+
|
95
|
+
for($n=0; $n<count($rssdataRaw); $n++){
|
96
|
+
|
97
|
+
//URL設定
|
98
|
+
|
99
|
+
$rssdata = simplexml_load_string($rssdataRaw[$n]);
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
if($rssdata->channel->item) $rssdata = $rssdata->channel;
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
if($rssdata->item){
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
foreach($rssdata->item as $myEntry){
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
### $sitetitle = $myEntry->channel->title;
|
116
|
+
|
117
|
+
$outdata[myDateGNU]['siteTitle'] = $sitetitle;
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
//日付
|
122
|
+
|
123
|
+
$rssDate = $myEntry->pubDate;
|
124
|
+
|
125
|
+
if(!$rssDate) $rssDate = $myEntry->children("http://purl.org/dc/elements/1.1/")->date;
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
//管理人
|
130
|
+
|
131
|
+
$myAuther = $myEntry->children("http://purl.org/dc/elements/1.1/")->creator;
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
date_default_timezone_set('Asia/Tokyo');
|
136
|
+
|
137
|
+
$myDateGNU = strtotime($rssDate);
|
138
|
+
|
139
|
+
$myDate = date('Y/m/d',$myDateGNU);
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
//タイトル
|
148
|
+
|
149
|
+
$myTitle = $myEntry->title;
|
150
|
+
|
151
|
+
$outdata[$myDateGNU]['myTitle'] = $myTitle;
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
//概要
|
156
|
+
|
157
|
+
$myDescription = $myEntry->description;
|
158
|
+
|
159
|
+
$outdata[$myDateGNU]['myDescription'] = $myDescription;
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
//リンクURL
|
164
|
+
|
165
|
+
$myLink = $myEntry->link;
|
166
|
+
|
167
|
+
$outdata[$myDateGNU]['myLink'] = $myLink;
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
//日付
|
172
|
+
|
173
|
+
$outdata[$myDateGNU]['rssDate'] = $rssDate;
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
//管理人
|
178
|
+
|
179
|
+
$outdata[$myDateGNU]['myAuther'] = $myAuther;
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
//ソート用
|
184
|
+
|
185
|
+
$outdata[$myDateGNU]['myDateGNU'] = $myDateGNU;
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
//出力内容(CSSOK)
|
190
|
+
|
191
|
+
if(preg_match('/PR:/',$myTitle)) continue;
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
$date = array();
|
204
|
+
|
205
|
+
foreach($outdata as $key => $row){
|
206
|
+
|
207
|
+
$date[$key] = $row['myDateGNU'];
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
array_multisort($date, SORT_DESC, SORT_NUMERIC, $outdata);
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
//記事情報取得
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
$dataList = array();
|
222
|
+
|
223
|
+
$dataList = $outdata; //適当に記事データを取得する処理
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
//XMLの記事部分作成
|
228
|
+
|
229
|
+
$item = "";
|
230
|
+
|
231
|
+
foreach($dataList as $value){
|
232
|
+
|
233
|
+
$item .= "<item>n";
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
### $itemSitetitle = $value['siteTitle'];
|
238
|
+
|
239
|
+
$item .= "<siteTitle>" . $itemSitetitle . "</siteTitle>n";
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
//タイトル
|
244
|
+
|
245
|
+
$itemTitle = $value['myTitle'];
|
246
|
+
|
247
|
+
$item .= "<title>" . $itemTitle . "</title>n";
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
//概要
|
252
|
+
|
253
|
+
$itemDescription = $value['myDescription'];
|
254
|
+
|
255
|
+
$item .= "<description>" . $itemDescription . "</description>n";
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
//リンク
|
260
|
+
|
261
|
+
$itemLink = $value['myLink'];
|
262
|
+
|
263
|
+
$item .= "<link>" . $itemLink . "</link>n";
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
//管理人
|
268
|
+
|
269
|
+
$itemAuther = $value['myAuther'];
|
270
|
+
|
271
|
+
$item .= "<author>" . $itemAuther . "</author>n";
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
//更新日付
|
276
|
+
|
277
|
+
$itemPubDate = $value['rssDate'];
|
278
|
+
|
279
|
+
$itemPubDate = date('m/d G:i', strtotime($itemPubDate));
|
280
|
+
|
281
|
+
$item .= "<pubDate>$itemPubDate</pubDate>n";
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
$item .= "</item>n";
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
//XML下部分作成
|
294
|
+
|
295
|
+
$rssFooter = <<<RSS
|
296
|
+
|
297
|
+
</channel>
|
298
|
+
|
299
|
+
</rss>
|
300
|
+
|
301
|
+
RSS;
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
//XML出力
|
306
|
+
|
307
|
+
echo $rssHeader.$item.$rssFooter;
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
//同時呼び出し関数
|
312
|
+
|
313
|
+
function multiRequest($data, $options = array()) {
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
// array of curl handles
|
318
|
+
|
319
|
+
$curly = array();
|
320
|
+
|
321
|
+
// data to be returned
|
322
|
+
|
323
|
+
$result = array();
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
// multi handle
|
328
|
+
|
329
|
+
$mh = curl_multi_init();
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
// loop through $data and create curl handles
|
334
|
+
|
335
|
+
// then add them to the multi-handle
|
336
|
+
|
337
|
+
foreach ($data as $id => $d) {
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
$curly[$id] = curl_init();
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
$url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
|
346
|
+
|
347
|
+
curl_setopt($curly[$id], CURLOPT_URL, $url);
|
348
|
+
|
349
|
+
curl_setopt($curly[$id], CURLOPT_HEADER, 0);
|
350
|
+
|
351
|
+
curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
// post?
|
356
|
+
|
357
|
+
if (is_array($d)) {
|
358
|
+
|
359
|
+
if (!empty($d['post'])) {
|
360
|
+
|
361
|
+
curl_setopt($curly[$id], CURLOPT_POST, 1);
|
362
|
+
|
363
|
+
curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']);
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
// extra options?
|
372
|
+
|
373
|
+
if (!empty($options)) {
|
374
|
+
|
375
|
+
curl_setopt_array($curly[$id], $options);
|
376
|
+
|
377
|
+
}
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
curl_multi_add_handle($mh, $curly[$id]);
|
382
|
+
|
383
|
+
}
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
// execute the handles
|
388
|
+
|
389
|
+
$running = null;
|
390
|
+
|
391
|
+
do {
|
392
|
+
|
393
|
+
curl_multi_exec($mh, $running);
|
394
|
+
|
395
|
+
} while($running > 0);
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
// get content and remove handles
|
400
|
+
|
401
|
+
foreach($curly as $id => $c) {
|
402
|
+
|
403
|
+
$result[$id] = curl_multi_getcontent($c);
|
404
|
+
|
405
|
+
curl_multi_remove_handle($mh, $c);
|
406
|
+
|
407
|
+
}
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
// all done
|
412
|
+
|
413
|
+
curl_multi_close($mh);
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
return $result;
|
418
|
+
|
419
|
+
}
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
?>
|