Skip to content

Instantly share code, notes, and snippets.

@zappingseb
Last active February 12, 2019 05:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zappingseb/e02bed95a46839756df14ac167c8b469 to your computer and use it in GitHub Desktop.
Save zappingseb/e02bed95a46839756df14ac167c8b469 to your computer and use it in GitHub Desktop.
Medium to r-bloggers
<?php
header('Content-Type: text/xml');
$xml = new DOMDocument;
$url = "https://medium.com/feed/@zappingseb";
$xml->load($url);
$book = $xml->documentElement;
// we retrieve the chapter and remove it from the book
$channel= $book->getElementsByTagName('channel')->item(0);
$items = $channel->getElementsByTagName('item');
$domArray = array(); //set up an array to catch all our nodes
foreach ($items as $i){
//echo $i->nodeValue;
//$title = $i->getElementsByTagName('title')->item(0);
//echo $title->nodeValue;
//echo "xx<br/>";
$categories = $i->getElementsByTagName('category');
$found = false;
foreach($categories as $category){
if($category->nodeValue == "r"){
$found = true;
break;
}
}
if(!$found){
$domArray[] = $i;
}
}
foreach($domArray as $i){
$channel->removeChild($i);
}
echo $xml->saveXML();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment