Küzdöttem a Zend Framework-kel, hogy beolvassa a ‘content:encoded’ tag-eket egy RSS feedből. Az alábbi kóddal sikerült:
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
| <?php
public function indexAction()
{
$ns = array
(
'content' => 'http://purl.org/rss/1.0/modules/content/',
'wfw' => 'http://wellformedweb.org/CommentAPI/',
'dc' => 'http://purl.org/dc/elements/1.1/',
);
Zend_Loader::loadClass('Zend_Feed');
try {
$rssFeed = Zend_Feed::import('http://blog.linuxforge.hu/feed');
} catch (Zend_Feed_Exception $e) {
echo "Exception caught importing feed: {$e->getMessage()}\n";
exit;
}
$channel = array(
'title' => $rssFeed->title(),
'link' => $rssFeed->link(),
'description' => $rssFeed->description(),
'items' => array(),
);
$i = 0;
$xml = new SimpleXMLElement($rssFeed->saveXML());
foreach ($rssFeed as $item) {
$content = $xml->channel->item[$i++]->children($ns['content']);
$channel['items'][] = array(
'title' => $item->title(),
'link' => $item->link(),
'description' => $item->description(),
'content' => trim($content->encoded),
);
}
$this->view->channel = $channel;
}
|