Skip to content

Instantly share code, notes, and snippets.

View noah-st-amand's full-sized avatar

noah-st-amand

View GitHub Profile
@noah-st-amand
noah-st-amand / _xml_to_array.php
Created September 9, 2020 17:26
XML to Array (with namespaced elements)
<?php
/**
* Given the URL of an XML file, fetch the contents and pass it to _xml_to_array() to be
* converted to an associative array. The file is read into a string and then parsed via
* simplexml_load_string() (rather than parsed directly with simplexml_load_file()),
* because the "LIBXML_NOCDATA" parameter is required in order for CDATA to persist.
*/
function _xml_to_array_from_file($url) {
$array = NULL;
if ($file = file_get_contents($url)) {