Skip to content

Instantly share code, notes, and snippets.

@imanilchaudhari
Created July 14, 2016 10:15
Show Gist options
  • Save imanilchaudhari/ba8b77ba24f2a2fbddccb927216db495 to your computer and use it in GitHub Desktop.
Save imanilchaudhari/ba8b77ba24f2a2fbddccb927216db495 to your computer and use it in GitHub Desktop.
<?php
namespace backend\components;
class XmlToJson {
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment