Blog
tags: news software php deutsch opensource osbn
Permalink: https://musicchris.de/blog?id=15&langopt=english
08.Oct.2014 16:29 - last update: 01.Sep.2016 11:48
no comments
Kleiner php-Parser für den OSBN-Feed
Heute habe ich mal den OSBN-Ticker bei mir eingebaut. Es scheint da schon Lösungen zu geben, aber fertige Sachen einbauen; das kann ja jeder. Daher möchte ich hier mal meine Lösung vorstellen.
Genau genommen lese ich nur die feed.rss in ein Array, durchsuche dieses anschließend nach <link> und <title>, lösche dann alle tags, und spucke das übrig gebliebene als kleine Liste aus. Das wars schon!
Mehr Daten brauche ich nicht für meinen kleinen Newsticker, was sich aber sehr einfach erweitern ließe...
Hier also der Code:
<?php
$feed = file("http://osbn.de/feed.rss");
$item = 0;
foreach ($feed as $key => $value)
{
$feed[$key] = trim($value);
$feed[$key] = html_entity_decode($feed[$key]);
if (strcmp($feed[$key],"<item>") == 0) $item++;
if ($item == 0) { unset($feed[$key]); continue; }
if ($item > 0 and $item < 9)
{
if (strncmp($feed[$key],"<link>",6) == 0 or strncmp($feed[$key],"<title>",7) == 0)
{
if (strncmp($feed[$key],"<link>",6) == 0) $descr = "link";
if (strncmp($feed[$key],"<title>",7) == 0) $descr = "title";
$tags = array("<link>", "</link>", "<title>", "</title>", "<![CDATA[", "]]>");
$data[$item][$descr] = str_replace($tags, "", $feed[$key]);
}
else { unset($feed[$key]); continue; }
}
}
unset($feed);
echo "<ul>\n";
foreach ($data as $item => $value)
{
echo "<li><a href=\"{$data[$item][link]}\" target=\"_blank\">{$data[$item][title]}</a></li>\n";
}
echo "</ul>\n";
?>
Zu sehen ist das ganze dann auf meiner Startseite.
Über Verbesserungsvorschläge würde ich mich natürlich sehr freuen!
comments
post a comment
privacy declaration
Your IP-address, useragent-string etc are not stored by this blog-software. Still, it is possible that the hoster of this website may store data like this. But that is beyond the scope of this blog-software. Check out this website's privacy declaration to find out more about that!
This blog-software generally doesn't store any information about you. Only if you post a comment, some data will have to be stored. You don't have to input any personal information here. Except for the comment itself, all fields are optional!
If you don't want to tells us your name, that's fine. It will be shown as 'anonymous'.
If you want to receive notifications on following comments, naturally you'll have to give us your email address. It will be stored and not be shared with anybody. If you don't want to be notified, just leave the notifications field empty.
If you want your name to be linked to your website, you'll have to give us your site's address. Otherwise leave this field empty.
This data will be stored in case you decide to post a comment here: