sammyjo20 / xml-to-array
Convert an XML string into an easy to understand array
Installs: 2 669
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- ext-dom: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.5
- pestphp/pest: ^1.21
- spatie/array-to-xml: ^3.1
README
This package provides an easy way to convert an XML string into an array.
Inspired by Spatie's array-to-xml.
Install
You can install this package with Composer.
composer require sammyjo20/xml-to-array
Usage
<?php use Sammyjo20\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);
Result
array:1 [ "items" => array:2 [ "good_guy" => array:2 [ "name" => "Luke Skywalker" "weapon" => "Lightsaber" ] "bad_guy" => array:2 [ "name" => "Sauron" "weapon" => "Evil Eye" ] ] ]
Thank you to the original creator
This package was originally created by vyuldashev. This package is an up-to-date version with some bugs fixed. Click here to view the original package.