Created
September 15, 2014 17:00
-
-
Save chrisdiana/b2c604c99409d0cd2a0b to your computer and use it in GitHub Desktop.
SimpleXML Strip CDATA
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
<?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); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot !