多维/xml-array

从 XML 文件创建数组。

1.0.0 2019-02-20 01:29 UTC

This package is auto-updated.

Last update: 2024-09-20 14:41:08 UTC


README

Build Status Latest Stable Version Code Coverage Minimum PHP Version License Total Downloads Scrutinizer Code Quality

这是一个非常简单和基础的库,可以从格式良好的 XML 输入创建 PHP 数组。这个库与我们的 DOM-Array 库相反,后者将数组转换为 XML 文件。

要求

  • PHP 5.5+

安装

安装此库最简单的方法是使用 composer。要安装,只需在您的 composer.json 文件中包含以下内容

"require": {
    "multidimensional/xml-array": "*"
}

或者在终端或 shell 中运行以下命令

composer require --prefer-dist multidimensional/xml-array

您也可以指定版本约束,更多信息请参见 这里

用法

此库使用 PSR-4 自动加载,所以请确保您在类文件顶部包含库

use Multidimensional\XmlArray\XMLArray;

如何在您的代码中使用

$xml = '<tag>Value</tag>';
$array = XMLArray::generateArray($xml);
print_r($array);

//$array = array("tag" => array(0 => 'Value'));

默认情况下,该库将转换属性,并在属性名称前添加 @。您可以通过将 generateArray 的第二个参数设置为 false 来禁用属性的转换。

设置为 false 时,属性将放在一个数组中,通常标记为值 '@attributes'。

空的 XML 将返回一个 null 数组。

贡献

我们非常感谢所有通过添加功能或改进现有功能来提高此库的帮助。如果您想为我们的库添加内容,请确保您使用 PSR-2 格式,并为所有添加的功能添加单元测试。

请随意分支并提交 pull 请求!

许可证

MIT License

Copyright (c) 2017 - 2019 multidimension.al

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.