PHP code example of refactorstudio / php-array-to-xml

1. Go to this page and download the library: Download refactorstudio/php-array-to-xml 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/ */

    

refactorstudio / php-array-to-xml example snippets




use RBoonzaijer\PhpArrayToXml\PhpArrayToXml;

$converter = new PhpArrayToXml();

$result = $converter->toXmlString(['title' => 'My Products']);

$array = [
  'title' => 'My Products',
  'pricing' => 'Pricing'
];

$result = $converter->setFormatOutput(true)->toXmlString($array);

// or use the alias:
$result = $converter->prettify()->toXmlString($array);

$result = $converter->setCustomRootName('data')->toXmlString();

$array = [
  'title' => 'My Products',
  'products' => [
    [
      'name' => 'Raspberry Pi 3',
      'price' => 39.99
    ],
    [
      'name' => 'Arduino Uno Rev3',
      'price' => 19.99
    ]
  ]
];

$xml_string = $converter->setCustomTagName('item')->toXmlString($array);

$xml_string = $converter->setVersion('1.1')->toXmlString(['test']);

$xml_string = $converter->setEncoding('ISO-8859-1')->toXmlString(['test']);

$array = [
  'some of these keys have' => 'My Value 1',
  'spaces in them' => 'My Value 2',
];

$xml_string = $converter->setSeparator('-')->toXmlString($array);

$array = [
  'This' => [
    'Is' => [
      'an',
      'Example'
    ]
  ]
];

$xml_string = $converter->setTransformTags('lowercase')->toXmlString($array);

$xml_string = $converter->setTransformTags('uppercase')->toXmlString($array);

$xml_string = $converter
              ->setTransformTags('uppercase')
              ->setCustomRootName('MyRoot')
              ->setCustomTagName('MyCustomTag')
              ->toXmlString($array);

$array = [
  'this',
  'is',
  'an'
  [
    'example',
    'using',
    'numeric tag suffix',
  ],
];

$xml_string = $converter->setNumericTagSuffix('_')->toXmlString($array);

$array = [
  'StringTrue' => 'true',
  'StringFalse' => 'false',
  'BooleanTrue' => true,
  'BooleanFalse' => false
];

$xml_string = $converter->setCastBooleanTrue('Yes')->setCastBooleanFalse('No')->toXmlString($array);

$array = [
  'StringNull' => 'null',
  'StringEmpty' => '',
  'RealNull' => null
];

$xml_string = $converter->setCastNullValue('__NULL__')->setCastBooleanFalse('No')->toXmlString($array);

composer