vyuldashev / xml-to-array
Convert xml to an array
Installs: 581 907
Dependents: 1
Suggesters: 0
Security: 0
Stars: 36
Watchers: 1
Forks: 16
Open Issues: 7
Requires
- php: ^7.1|^8.0
Requires (Dev)
- larapack/dd: ^1.1
- phpunit/phpunit: ^7.5|^9.5
- spatie/array-to-xml: ^2.7
This package is auto-updated.
Last update: 2024-10-24 03:59:18 UTC
README
This package provides a very simple class to convert an xml string to an array.
Inspired by Spatie's array-to-xml ❤️
Install
You can install this package via composer.
composer require vyuldashev/xml-to-array
Usage
use Vyuldashev\XmlToArray\XmlToArray; $xml = '<items> <good_guy> <name>Luke Skywalker</name> <weapon>Lightsaber</weapon> </good_guy> <bad_guy> <name>Sauron</name> <weapon>Evil Eye</weapon> </bad_guy> </items>'; $result = XmlToArray::convert($xml);
After running this piece of code $result
will contain:
array:1 [ "items" => array:2 [ "good_guy" => array:2 [ "name" => "Luke Skywalker" "weapon" => "Lightsaber" ] "bad_guy" => array:2 [ "name" => "Sauron" "weapon" => "Evil Eye" ] ] ]