承接 mtownsend/xml-to-array 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mtownsend/xml-to-array

最新稳定版本:2.0.0

Composer 安装命令:

composer require mtownsend/xml-to-array

包简介

Easily convert valid xml to a php array.

README 文档

README

Easily convert valid xml to a php array.

Installation

Install via composer:

composer require mtownsend/xml-to-array

Quick start

Using the class

use Mtownsend\XmlToArray\XmlToArray;

$xml = <<<XML
<?xml version="1.0"?>
<request>
    <carrier>fedex</carrier>
    <id>123</id>
    <tracking_number>9205590164917312751089</tracking_number>
</request>
XML;

$array = XmlToArray::convert($xml);

// $array is:
[
	'carrier' => 'fedex',
	'id' => '123',
	'tracking_number' => '9205590164917312751089'
];

Using the global helper

$xml = <<<XML
<?xml version="1.0"?>
<request>
    <carrier>fedex</carrier>
    <id>123</id>
    <tracking_number>9205590164917312751089</tracking_number>
</request>
XML;

$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

Credits

Testing

You can run the tests with:

./vendor/bin/phpunit

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 3.12M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 124
  • 点击次数: 1
  • 依赖项目数: 24
  • 推荐数: 1

GitHub 信息

  • Stars: 117
  • Watchers: 4
  • Forks: 14
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04