php-junior/laravel-xml 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

php-junior/laravel-xml

最新稳定版本:1.0.2

Composer 安装命令:

composer require php-junior/laravel-xml

包简介

A simple XML to Array converter for Laravel

README 文档

README

Latest Version on Packagist Total Downloads

This package is a simple XML to Array converter for Laravel.

Installation

You can install the package via composer:

composer require php-junior/laravel-xml

Usage

default xml root tag is root

use Illuminate\Support\Arr;

$data = [
    'name' => 'John Doe',
    'description' => 'This is a <strong>description</strong>',
    'bio01' => 'This is a <strong>bio01</strong>',
    'bio02' => 'This is a <strong>bio02</strong>',
    'bio03' => 'This is a <strong>bio03</strong>',
    'bio04' => 'This is a <strong>bio04</strong>',
];

$xml = Arr::toXml($data);
<root>
    <name>John Doe</name>
    ...
</root>

// change root tag
$xml = Arr::toXml($data, 'user');
<user>
    <name>John Doe</name>
    ...
</user>

// cdata tag
$xml = Arr::toXml($data, 'user', ['description']);
<user>
    <name>John Doe</name>
    <description><![CDATA[This is a <strong>description</strong>]]></description>
    ...
</user>

// cdata wildcard tag
$xml = Arr::toXml($data, 'user', ['bio*']);
<user>
    <name>John Doe</name>
    <bio01><![CDATA[This is a <strong>bio01</strong>]]></bio01>
    <bio02><![CDATA[This is a <strong>bio02</strong>]]></bio02>
    <bio03><![CDATA[This is a <strong>bio03</strong>]]></bio03>
    <bio04><![CDATA[This is a <strong>bio04</strong>]]></bio04>
</user>

// multi-dimensional array
Arr::toXml([
    'user' => [
        [
            'name' => 'User',
            'email' => 'user@user.com'
        ],
        [
            'name' => 'User 2',
            'email' => 'user2@user.com'
        ],
    ]
], 'users');
<users>
    <user>
        <name>User</name>
        <email>user@user.com</email>
    </user>
    <user>
        <name>User 2</name>
        <email>user2@user.com</email>
    </user>
</users>

// xml to array
$data = Arr::fromXml($xml);
[
    'name' => 'John Doe',
    'description' => 'This is a <strong>description</strong>',
    'bio01' => 'This is a <strong>bio01</strong>',
    'bio02' => 'This is a <strong>bio02</strong>',
    'bio03' => 'This is a <strong>bio03</strong>',
    'bio04' => 'This is a <strong>bio04</strong>',
]

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email nyinyilwin1992@hotmail.com instead of using the issue tracker.

License

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

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-15