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.
SimpleXML Strip CDATA
<?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);
?>
@slawomiroruba
Copy link

Thanks a lot !

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