Skip to content

Instantly share code, notes, and snippets.

@chrisdiana
chrisdiana / gist:b2c604c99409d0cd2a0b
Created September 15, 2014 17:00
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