telton / xml-to-array
A PHP package to convert an XML string to an array.
Installs: 86
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/telton/xml-to-array
Requires
- php: >=7.0
- ext-dom: *
Requires (Dev)
- phpunit/phpunit: ^7.4
This package is auto-updated.
Last update: 2020-01-24 20:45:42 UTC
README
This is a PHP package that converts an XML string to an array.
To use:
/** * XML Structure: * * <tag> * <announcement>This is awesome!</announcement> * <author>Tyler Elton</author> * </tag> **/ $array = \Telton\XMLToArray\XMLToArray::convert($xml); /** * Converted array: * * [ * 'announcement' => 'This is awesome!', * 'author' => 'Tyler Elton' * ] **/
There is an optional flag in convert() that will add the root tag as well:
/** * XML Structure: * * <tag> * <announcement>This is awesome!</announcement> * <author>Tyler Elton</author> * </tag> **/ $array = \Telton\XMLToArray\XMLToArray::convert($xml, true); /** * Converted array: * * [ * 'announcement' => 'This is awesome!', * 'author' => 'Tyler Elton', * 'root' => 'tag' * ] **/
If the XML has attribute tags, it will convert them like this:
/** * XML Structure: * * <tag type="announcement"> * <announcement>This is awesome!</announcement> * <author role="developer">Tyler Elton</author> * </tag> **/ $array = \Telton\XMLToArray\XMLToArray::convert($xml, true); /** * Converted array: * * [ * 'announcement' => 'This is awesome!', * 'author' => [ * 'value' => 'Tyler Elton', * 'role' => 'developer' * ], * 'root' => 'tag', * 'type' => 'announcement' * ] **/