Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mtownsend5512/xml-to-array
Easily convert valid xml to a php array.
https://github.com/mtownsend5512/xml-to-array
api array convert xml xml-files xml-parser xml-to-array
Last synced: 14 days ago
JSON representation
Easily convert valid xml to a php array.
- Host: GitHub
- URL: https://github.com/mtownsend5512/xml-to-array
- Owner: mtownsend5512
- License: mit
- Created: 2018-10-17T14:32:03.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-02-27T22:39:59.000Z (over 3 years ago)
- Last Synced: 2024-10-15T08:41:12.064Z (29 days ago)
- Topics: api, array, convert, xml, xml-files, xml-parser, xml-to-array
- Language: PHP
- Size: 5.86 KB
- Stars: 110
- Watchers: 4
- Forks: 14
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Easily convert valid xml to a php array.
## Installation
Install via composer:
```
composer require mtownsend/xml-to-array
```## Quick start
### Using the class
```php
use Mtownsend\XmlToArray\XmlToArray;$xml = <<
fedex
123
9205590164917312751089XML;
$array = XmlToArray::convert($xml);
// $array is:
[
'carrier' => 'fedex',
'id' => '123',
'tracking_number' => '9205590164917312751089'
];```
### Using the global helper
```php
$xml = <<fedex
123
9205590164917312751089XML;
$array = xml_to_array($xml);
// $array is:
[
'carrier' => 'fedex',
'id' => '123',
'tracking_number' => '9205590164917312751089'
];
```## Helpers, methods, and arguments
**Static method**
``XmlToArray::convert($xml, $outputRoot = false)``
The ``$outputRoot`` determines whether or not the php array will have a ``@root`` key. Default is ``false``.
**Helper**
``xml_to_array($xml, $outputRoot = false)``
Arguments are identical to ``XmlToArray::convert`` method.
## Purpose
XML has always been a challenge to work with in PHP compared to other data formats, such as JSON. This package aims to make integrating with XML files or api requests significantly easier. With this package, you might actually like interfacing with XML in your application now.
## Other packages you may be interested in
- [mtownsend/collection-xml](https://github.com/mtownsend5512/collection-xml)
- [mtownsend/request-xml](https://github.com/mtownsend5512/request-xml)
- [mtownsend/response-xml](https://github.com/mtownsend5512/response-xml)## Credits
- Mark Townsend
- Adrien aka Gaarf
- [All Contributors](../../contributors)## Testing
You can run the tests with:
```bash
./vendor/bin/phpunit
```## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.