nkrumahthis/xml-to-array

Parses an XML string into an array

v0.1.0-alpha 2024-02-23 08:28 UTC

This package is not auto-updated.

Last update: 2025-09-06 17:48:26 UTC


README

A simple PHP library for parsing XML strings into associative arrays.

Installation

You can install this package via Composer:

composer require nkrumahthis/xml-to-array

Usage

use Nkrumahthis\XMLToArray\XMLToArray;

$xmlString = '<?xml version="1.0" encoding="UTF-8"?>
    <root>
        <name>John Doe</name>
        <age>30</age>
        <city>New York</city>
    </root>';

$array = XMLToArray::parse($xmlString);

print_r($array);

This will output

Array
(
    [root] => Array
        (
            [name] => John Doe
            [age] => 30
            [city] => New York
        )
)

Testing

To run PHPUnit tests, use:

vendor/bin/phpunit .

Contributing

Contributions are welcome! Feel free to submit pull requests or open issues on GitHub: nkrumahthis/xml-to-array.

License

This package is licensed under the MIT License. See the LICENSE file for details.