PHP code example of fernandoebert / xml-tools

1. Go to this page and download the library: Download fernandoebert/xml-tools library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fernandoebert / xml-tools example snippets




ernandoebert\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;



ernandoebert\XmlTools\xmlTools;

$xml = '<?xml version=\"1.0\" encoding=\"UTF-8\"

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]



ernandoebert\XmlTools\xmlTools;

$xml = '<?xml version=\"1.0\" encoding=\"UTF-8\"

Array
(
  [key01] => value01
  [key02] => value02
  [key03] => Array 
    (
      [subkey01] => Array
        (
            [0] => item01
            [1] => item02
            [2] => item03
            [3] => item04
        )
    )
)