定制 fernandoebert/xml-tools 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

fernandoebert/xml-tools

Composer 安装命令:

composer require fernandoebert/xml-tools

包简介

A simple class for working with XML in PHP

README 文档

README

A simple class for working with XML in PHP

Uma simples classe para trabalhar com XML no PHP

Installation

xml-tools is available via Composer:

"fernandoebert/xml-tools": "1.*"

or run

composer require fernandoebert/xml-tools

Documentation

For more details on how to use it, see the example folder with details in the component directory.

Para mais detalhes sobre como usar, veja a pasta de exemplo com detalhes no diretório do componente.

xml_encode
<?php

include __DIR__ . "/../vendor/autoload.php";

use Fernandoebert\XmlTools\xmlTools;

$example = [
    "root" => [
        "key01" => [
            '_value' => "Value Of _value"
        ],
        "key02" => [
            '_cdata' => "Value of CDATA",
        ],
        "key03" => [
            '@attr' => [
                'key01' => 'ValuesOfAttr01',
                'key02' => 'valuesOfAttr02',
                'key03' => 'valuesOfAttr03',
            ],
            'subkey01' => [
                'item01',
                'item02',
                'item03',
                'item04',
            ]
        ]
    ]
];
// to not use the Content-type header, use the second parameter ($header) as false
// $xml = xmlTools::xml_encode($example, false);
$xml = xmlTools::xml_encode($example);
echo $xml;
Result
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <key01>Value Of _value</key01>
    <key02>
        <![CDATA[ Value of CDATA ]]>
    </key02>
    <key03 key01="ValuesOfAttr01" key02="valuesOfAttr02" key03="valuesOfAttr03">
        <subkey01>item01</subkey01>
        <subkey01>item02</subkey01>
        <subkey01>item03</subkey01>
        <subkey01>item04</subkey01>
    </key03>
</root>
xml_decode in OBJ STDCLASS
<?php

include __DIR__ . "/../vendor/autoload.php";

use Fernandoebert\XmlTools\xmlTools;

$xml = '<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>...</root>';

echo "<pre>";
print_r(xmlTools::xml_decode($xml));
echo "</pre>";
Result
stdClass Object
(
  [key01] => value01
  [key02] => value02
  [key03] => stdClass Object
    (
      [subkey01] => Array
        (
            [0] => item01
            [1] => item02
            [2] => item03
            [3] => item04
        )

    )
)

// When the index is numeric, returns an array. Ex: [subkey01]
xml_decode in ARRAY
<?php

include __DIR__ . "/../vendor/autoload.php";

use Fernandoebert\XmlTools\xmlTools;

$xml = '<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>...</root>';

echo "<pre>";
print_r(xmlTools::xml_decode($xml, true));
echo "</pre>";
Result
Array
(
  [key01] => value01
  [key02] => value02
  [key03] => Array 
    (
      [subkey01] => Array
        (
            [0] => item01
            [1] => item02
            [2] => item03
            [3] => item04
        )
    )
)

Support

If you discover a security issue, send an email to fernandoebert@ebertsystem.com

Se você descobrir algum problema relacionado à segurança, envie um e-mail para fernandoebert@ebertsystem.com

Thank you

Credits

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固