XML_Serializer
[ class tree: XML_Serializer ] [ index: XML_Serializer ] [ all elements ]

Source for file serializeIndexedArrayWithContext.php

Documentation is available at serializeIndexedArrayWithContext.php

  1. <?PHP
  2. /**
  3.  * This example demonstrates the use of
  4.  * mode => simplexml
  5.  *
  6.  * It can be used to serialize an indexed array
  7.  * like ext/simplexml does, by using the name
  8.  * of the parent tag, while omitting this tag.
  9.  *
  10.  * @author Stephan Schmidt <schst@php.net>
  11.  */
  12.     error_reporting(E_ALL);
  13.     
  14.     require_once 'XML/Serializer.php';
  15.  
  16.     $options = array(
  17.                         XML_SERIALIZER_OPTION_INDENT       => '    ',
  18.                         XML_SERIALIZER_OPTION_LINEBREAKS   => "\n",
  19.                         XML_SERIALIZER_OPTION_DEFAULT_TAG  => array(),
  20.                         XML_SERIALIZER_OPTION_DEFAULT_TAG  => array('foos' => 'foo''bars' => 'bar')
  21.                     );
  22.     
  23.     $serializer = new XML_Serializer($options);
  24.     
  25.     $data = array(
  26.                     'foos' => array('one foo''two foos''three foos'),
  27.                     'bars' => array('one bar''two bars''three bars'),
  28.                 );
  29.  
  30.     $result $serializer->serialize($data);
  31.     
  32.     if$result === true {
  33.         echo    '<pre>';
  34.         echo    htmlentities($serializer->getSerializedData());
  35.         echo    '</pre>';
  36.     }
  37. ?>

Documentation generated on Mon, 11 Mar 2019 14:14:04 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.