Skip to content

A simple class to convert an xml to array

License

Notifications You must be signed in to change notification settings

ikudosi/xml-to-array

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Convert xml to an array

Latest Version Software License Build Status Quality Score StyleCI Total Downloads

This package provides a very simple class to convert an xml string to an array.

Inspired by Spatie's array-to-xml ❤️

Install

You can install this package via composer.

composer require vyuldashev/xml-to-array

Usage

use Vyuldashev\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);

After running this piece of code $result will contain:

array:1 [
  "items" => array:2 [
    "good_guy" => array:2 [
      "name" => "Luke Skywalker"
      "weapon" => "Lightsaber"
    ]
    "bad_guy" => array:2 [
      "name" => "Sauron"
      "weapon" => "Evil Eye"
    ]
  ]
]

About

A simple class to convert an xml to array

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%