giunashvili/xml-parser
Composer 安装命令:
composer require giunashvili/xml-parser
包简介
This is simple package to parse array into xml simply and easy.
README 文档
README
XML Parser is a simple php package to parse xml in and out simply and easy.
you could:
- Parse array into xml
- Parse xml into array
Installation
Installation is fairly simple:
$ composer require giunashvili/xml-parser
Usage
Array into XML
use Giunashvili\XMLParser\Parse; $arr = [ 'animals' => [ 'bear' => 'black', 'fox' => 'red', 'Kangaroo' => 'Jack' ], 'plants' => [ 'bamboo', 'apple' ] ]; $xmlWithoutDefinedWrapper = Parse :: arrayAsXml( $arr ); echo $xmlWithoutDefinedWrapper; /** <data> <animals> <bear> black </bear> <fox> red </fox> <Kangaroo> Jack </Kangaroo> </animals> <plants> <item-0> bamboo </item-0> <item-1> bamboo </item-1> </plangs> </data> */ $xmlWithDefinedWrapper = Parse :: arrayAsXml( $arr, 'classifications' ); echo $xmlWithoutDefinedWrapper; /** <classifications> <animals> <bear> black </bear> <fox> red </fox> <Kangaroo> Jack </Kangaroo> </animals> <plants> <item-0> bamboo </item-0> <item-1> bamboo </item-1> </plangs> </classifications> */
XML into Array
use Giunashvili\XMLParser\Parse; $xml = '<data>'. '<animals>'. '<bear>'. 'black'. '</bear>'. '<fox>'. 'red'. '</fox>'. '<Kangaroo>'. 'Jack'. '</Kangaroo>'. '</animals>'. '<plants>'. '<item-0>'. 'bamboo'. '</item-0>'. '<item-1>'. 'bamboo'. '</item-1>'. '</plangs>'. '</data>'; $arr = Parse :: xmlAsArray( $xml ); print_r( $arr ); /** [ 'classification' => [ [ 'animals' => [ 'bear' => 'black', 'fox' => 'red', 'Kangaroo' => 'Jack' ], 'plants' => [ 'item-0' => 'bamboo', 'item-1' => 'apple' ] ] ] ] */
统计信息
- 总下载量: 463
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-05-22