code-snippets

Some (maybe) useful snippets of code
git clone https://git.ortlepp.eu/code-snippets.git
Log | Files | Refs | README

commit ac4b8cdc3977b5465aa72d19c35546da9e47cef6
parent 8d3c652abafb84acf5fb52bff544d79b7be1848a
Author: Thorsten Ortlepp <post@ortlepp.eu>
Date:   Tue, 24 Sep 2019 22:51:36 +0200

Added 'Heise RSS' script

Diffstat:
MREADME.md | 7+++++++
Aphp/heise-rss/feed.php | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -1,3 +1,10 @@ # Code Snippets This repository contains some maybe useful snippets of code. + + +## PHP + +### Heise RSS + +A script to remove unwanted articles from Heise Online RSS feed. diff --git a/php/heise-rss/feed.php b/php/heise-rss/feed.php @@ -0,0 +1,52 @@ +<?php + +// A script to remove unwanted articles from Heise Online RSS feed +// Code based on and inspired by https://github.com/fuzzy76/rssfilter/blob/master/rssfilter.php + +// Set proper MIME type and encoding +header('Content-Type: application/rss+xml; charset=utf-8'); + +// Process the original feed +$xml = simplexml_load_file('https://www.heise.de/rss/heise.rdf'); +$ix = 0; +while ($ix < count($xml->channel->item) ) { + if ( filter_title($xml->channel->item[$ix]->title) || filter_url($xml->channel->item[$ix]->link) ) { + unset($xml->channel->item[$ix]); + } else { + $ix++; + } +} +echo $xml->asXML(); + +// Filter by article title +function filter_title($title) { + if (strpos($title, 'heise+') !== false) { + return true; + } + if (strpos($title, 'heise-Angebot') !== false) { + return true; + } + if (strpos($title, 'Anzeige: ') !== false) { + return true; + } + return false; +} + +// Filter by article URL +function filter_url($url) { + if (strpos($url, 'www.techstage.de') !== false) { + return true; + } + if (strpos($url, '/autos/') !== false) { + return true; + } + if (strpos($url, '/foto/') !== false) { + return true; + } + if (strpos($url, '/mac-and-i/') !== false) { + return true; + } + return false; +} + +?>