Skip to content

Instantly share code, notes, and snippets.

@srsad
Created March 18, 2018 12:49
Show Gist options
  • Save srsad/82b29ccb75f9ca24ff5c9bacd78c3dba to your computer and use it in GitHub Desktop.
Save srsad/82b29ccb75f9ca24ff5c9bacd78c3dba to your computer and use it in GitHub Desktop.
<?php
class Xml2Json {
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;
}
}
print Xml2Json::Parse($file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment