sammyjo20/xml-to-array

This package is abandoned and no longer maintained. No replacement package was suggested.

Convert an XML string into an easy to understand array

v1.0.0 2022-02-04 22:32 UTC

This package is auto-updated.

Last update: 2023-12-02 21:40:56 UTC


README

Build Status

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.