Skip to content

Instantly share code, notes, and snippets.

@BilalBudhani
Created January 31, 2013 10:04
Show Gist options
  • Save BilalBudhani/4681837 to your computer and use it in GitHub Desktop.
Save BilalBudhani/4681837 to your computer and use it in GitHub Desktop.
PHP function to convert simple RSS to JSON
public function Parse ($url) {
$fileContents= file_get_contents($url);
$fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents);
$fileContents = trim(str_replace('"', "'", $fileContents));
$simpleXml = simplexml_load_string($fileContents);
$json = json_encode($simpleXml);
return $json;
}
@menjilx
Copy link

menjilx commented Aug 7, 2021

This one handles CDATA

function Parse($url){
     $simpleXml = simplexml_load_file($url, "SimpleXMLElement", LIBXML_NOCDATA);
     $json = json_encode($simpleXml);
     return $json;
}

https://repl.it/@vanduc1102/Rss-To-JSON-sample

this one works! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment