Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vyuldashev/xml-to-array
A simple class to convert an xml to array
https://github.com/vyuldashev/xml-to-array
api array php xml
Last synced: about 1 month ago
JSON representation
A simple class to convert an xml to array
- Host: GitHub
- URL: https://github.com/vyuldashev/xml-to-array
- Owner: vyuldashev
- License: mit
- Created: 2017-10-12T09:33:38.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-05-03T01:00:28.000Z (almost 2 years ago)
- Last Synced: 2024-12-19T04:06:45.819Z (about 2 months ago)
- Topics: api, array, php, xml
- Language: PHP
- Size: 21.5 KB
- Stars: 36
- Watchers: 1
- Forks: 16
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Convert xml to an array
[![Latest Stable Version](https://poser.pugx.org/vyuldashev/xml-to-array/v/stable?format=flat-square)](https://packagist.org/packages/vyuldashev/xml-to-array)
[![Build Status](https://github.com/vyuldashev/xml-to-array/workflows/Tests/badge.svg)](https://github.com/vyuldashev/xml-to-array/actions)
[![Total Downloads](https://poser.pugx.org/vyuldashev/xml-to-array/downloads?format=flat-square)](https://packagist.org/packages/vyuldashev/xml-to-array)
[![StyleCI](https://styleci.io/repos/106673178/shield)](https://styleci.io/repos/106673178)
[![License](https://poser.pugx.org/vyuldashev/xml-to-array/license?format=flat-square)](https://packagist.org/packages/vyuldashev/xml-to-array)This package provides a very simple class to convert an xml string to an array.
Inspired by Spatie's [array-to-xml](https://github.com/spatie/array-to-xml) ❤️
## Install
You can install this package via composer.
``` bash
composer require vyuldashev/xml-to-array
```## Usage
```php
use Vyuldashev\XmlToArray\XmlToArray;$xml = '
Luke Skywalker
Lightsaber
Sauron
Evil Eye
';$result = XmlToArray::convert($xml);
```
After running this piece of code `$result` will contain:```php
array:1 [
"items" => array:2 [
"good_guy" => array:2 [
"name" => "Luke Skywalker"
"weapon" => "Lightsaber"
]
"bad_guy" => array:2 [
"name" => "Sauron"
"weapon" => "Evil Eye"
]
]
]
```