rafrsr/lib-array2xml 问题修复 & 功能扩展

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

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

rafrsr/lib-array2xml

最新稳定版本:v1.0.1

Composer 安装命令:

composer require rafrsr/lib-array2xml

包简介

Array2XML conversion library

README 文档

README

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

XML2Array is a class to convert XML to an array in PHP. It returns an array which can be converted back to XML using the Array2XML class.

It can take a string XML as input or an object of type DOMDocument.

Installation

  1. Install composer
  2. Execute: composer require rafrsr/lib-array2xml

Usage

The usage is pretty simple. You have to include the class file in your code and call the following function.

$array = XML2Array::createArray($xml); print_r($array);

Example

The Following XML:

<?xml version="1.0" encoding="UTF-8"?> <movies type="documentary"> <movie> <title>PHP: Behind the Parser</title> <characters> <character> <name>Ms. Coder</name> <actor>Onlivia Actora</actor> </character> <character> <name>Mr. Coder</name> <actor>El ActÓr</actor> </character> </characters> <plot><![CDATA[So, this language. It's like, a programming language. Or is it a scripting language?  All is revealed in this thrilling horror spoof of a documentary.]]></plot> <great-lines> <line>PHP solves all my web problems</line> </great-lines> <rating type="thumbs">7</rating> <rating type="stars">5</rating> </movie> </movies>

will generate the following output:

array ( 'movies' => array ( 'movie' => array ( 'title' => 'PHP: Behind the Parser', 'characters' => array ( 'character' => array ( 0 => array ( 'name' => 'Ms. Coder', 'actor' => 'Onlivia Actora', ), 1 => array ( 'name' => 'Mr. Coder', 'actor' => 'El ActÓr', ), ), ), 'plot' => array ( '@cdata' => 'So, this language. It\'s like, a programming language. Or is it a scripting language?  All is revealed in this thrilling horror spoof of a documentary.', ), 'great-lines' => array ( 'line' => 'PHP solves all my web problems', ), 'rating' => array ( 0 => array ( '@value' => '7', '@attributes' => array ( 'type' => 'thumbs', ), ), 1 => array ( '@value' => '5', '@attributes' => array ( 'type' => 'stars', ), ), ), ), '@attributes' => array ( 'type' => 'documentary', ), ), )

References

This class is based on http://www.lalit.org/lab/convert-xml-to-array-in-php-xml2array/ with some minor bug fixed and support for php7

Copyright

This project is licensed under the MIT license.

统计信息

  • 总下载量: 35.33k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固