Skip to content

Instantly share code, notes, and snippets.

@chrisdiana
Created September 15, 2014 17:00
Show Gist options
  • Save chrisdiana/b2c604c99409d0cd2a0b to your computer and use it in GitHub Desktop.
Save chrisdiana/b2c604c99409d0cd2a0b to your computer and use it in GitHub Desktop.

Revisions

  1. chrisdiana created this gist Sep 15, 2014.
    13 changes: 13 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    <?php
    // Grab XML
    $xml_file = "rsform.xml";
    // Load xml data.
    $xml = file_get_contents($xml_file);
    // Strip whitespace between xml tags
    $xml = preg_replace('~\s*(<([^>]*)>[^<]*</\2>|<[^>]*>)\s*~','$1',$xml);
    // Convert CDATA into xml nodes.
    $xml = simplexml_load_string($xml,'SimpleXMLElement', LIBXML_NOCDATA);
    // Make variables
    // Return JSON.
    echo json_encode($xml);
    ?>