I have a problem with this function, because typing each XML child into an array can be problematic when the text is between the CDATA tags.
I fixed this by checking if the result of casting to an array is empty. If so, enter it in the string and you will get the correct result.
Here is my modified version with CDATA support:
function SimpleXML2ArrayWithCDATASupport($xml) { $array = (array)$xml; if (count($array) === 0) { return (string)$xml; } foreach ($array as $key => $value) { if (!is_object($value) || strpos(get_class($value), 'SimpleXML') === false) { continue; } $array[$key] = SimpleXML2ArrayWithCDATASupport($value); } return $array; }
Bo Pennings Jul 23 '14 at 19:57 2014-07-23 19:57
source share