<?
$ret=get_rss("http://subnets.ru/blog/?feed=rss2");
print "<table align=\"center\">";
printf("<tr><td class=head><a href=\"%s\" target=\"_blank\"><img src=\"img/rss.png\" border=\"0\" alt=\"RSS\" title=\"RSS\"></a></td><td class=head>%s</td></tr>",$u,$ret['rss_link'],$ret['rss_title'],$ret['rss_message']);
foreach ($ret['rss_mess_title'] as $tk=>$tv){
printf("<tr><td class=head>%s</td><td class=head3>%s</td>",$tk+1,date("d.m.Y H:i",strtotime($ret['rss_mess_date'][$tk])));
printf("<td class=head3><a href=\"%s\" target=\"_blank\">%s</a></td></tr>",$ret['rss_mess_link'][$tk],$ret['rss_mess_title'][$tk]);
if ($tk+1==5){
break;
}
}
print "</table>";
?>
<?
function get_rss($url){
$handle = fopen($url, "rb");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
$dom = new DOMDocument;
$dom->loadxml($contents);
if (!$dom) {
echo 'Error while parsing the document';
exit;
}
$s = simplexml_import_dom($dom);
$p = xml_parser_create();
xml_parse_into_struct($p, $contents, $vals, $index);
$from_enc=xml_parser_get_option($p,XML_OPTION_TARGET_ENCODING);
xml_parser_free($p);
$res['rss_title']=iconv($from_enc,"CP1251",$s->channel[0]->title);
$res['rss_link']=iconv($from_enc,"CP1251",$s->channel[0]->link);
$res['rss_message']=iconv($from_enc,"CP1251",$s->channel[0]->description);
foreach ($s->channel[0]->item as $k=>$v){
$res['rss_mess_title'][]=iconv($from_enc,"CP1251",$v->title);
$res['rss_mess_body'][]=iconv($from_enc,"CP1251",$v->description);
$res['rss_mess_link'][]=iconv($from_enc,"CP1251",$v->link);
$res['rss_mess_date'][]=date("d.m.Y H:i:s",strtotime(iconv($from_enc,"CP1251",$v->pubDate)));
}
return $res;
}
?>
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 4