ericmorand / xml-to-array
Simple XML-to-array converter
v1.0.1
2019-03-04 20:17 UTC
Requires
- ext-simplexml: *
Requires (Dev)
- phpunit/phpunit: ^6.4
This package is auto-updated.
Last update: 2024-11-05 20:34:12 UTC
README
This package provides a very simple converter to convert an XML string to an array. No attributes support, no complex logic, just a plain and simple converter that just works.
Installation
composer require ericmorand/xml-to-array
Usage
<?php use EricMorand\XMLToArray; $converter = new XMLToArray\Converter(); $xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?> <foo> <prop0/> <prop1>foo</prop1> <prop2><![CDATA[foo]]></prop2> <prop3> <prop0/> <prop1>foo</prop1> <prop2><![CDATA[foo]]></prop2> </prop3> </foo>"; $array = $converter->convertXML($xml);
By running this code, $array
would contain:
[ 'prop0' => null, 'prop1' => 'foo', 'prop2' => 'foo', 'prop3' => [ 'prop0' => null, 'prop1' => 'foo', 'prop2' => 'foo' ] ]