Created
January 31, 2013 10:04
-
-
Save BilalBudhani/4681837 to your computer and use it in GitHub Desktop.
PHP function to convert simple RSS to JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Thank you!
It works!
what about the !CDATA
<description>
<![CDATA[
What does it mean to be a man in 2019? The Men Who Raised Us podcast speaks to inspirational men from all walks of life on how their journey through adolescence shaped who they are today. This podcast is presented in partnership with The Fathering Project. New episodes are released every Monday and Thursday - listen and subscribe to hear more.
]]>
</description>
I'm getting
"description": {},
This one handles CDATA
function Parse($url){
$simpleXml = simplexml_load_file($url, "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode($simpleXml);
return $json;
}
This one handles CDATA
function Parse($url){ $simpleXml = simplexml_load_file($url, "SimpleXMLElement", LIBXML_NOCDATA); $json = json_encode($simpleXml); return $json; }
this one works! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great thank you!