Download the PHP package selfphp/data-converter without Composer
On this page you can find all versions of the php package selfphp/data-converter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download selfphp/data-converter
More information about selfphp/data-converter
Files in selfphp/data-converter
Package data-converter
Short Description Flexible data format converter library for PHP
License MIT
Informations about the package data-converter
selfphp/data-converter
A lightweight and extensible PHP library to convert structured data between formats.
Currently supports: array โ XML, XML โ array and array โ JSON conversion.
๐ Features
- โ Convert associative arrays to XML
- โ Convert XML to associative arrays
- โ Convert arrays to JSON (with optional flags)
- โ Convert JSON strings to associative arrays
- โ Custom root element name
- โ Optional XML declaration
- โ
Null โ
xsi:nilconversion - โ
Boolean โ string normalization (
true/false) - โ Recursive array handling
- โ Clean and readable output (pretty print)
- โ Invalid characters are automatically removed
- โ Minimal and modern code (no dependencies)
๐ฆ Installation
โ PHP 8.1 or higher required
โจ Usage Example
Array to XML
XML to Array
Array to JSON
JSON to Array
๐งช Tests
Run all PHPUnit tests:
๐ Project Structure
โ ๏ธ Limitations and Edge Cases
While the XmlToArrayConverter is suitable for most real-world use cases, there are a few edge cases and known limitations to be aware of:
โ Mixed Content
XML nodes with both text and child elements (mixed content) are not fully preserved. For example:
Would result in:
โ ๏ธ Empty Elements
Empty elements like <foo/> are interpreted as empty strings, not as null or empty arrays. If needed, you can post-process the result accordingly.
โ ๏ธ All values are strings
XML data types (numbers, booleans) are not automatically casted. For example:
Becomes:
โ XML Namespaces
Namespaces (e.g. xmlns or prefixed elements) are ignored and stripped automatically. Support for namespaces may be added in a future release.
If you encounter any of these scenarios in real-world data, feel free to contribute or open an issue ๐
๐ Planned
- [x] XML โ Array
- [x] JSON โ Array
- [ ] JSON โ XML
- [ ] CLI support (
php convert input.json) - [ ] Stream support
๐ License
MIT License โ free for personal and commercial use.