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.  
  13. require_once 'XML/Serializer.php';
  14.  
  15. $options = array(
  16.                     XML_SERIALIZER_OPTION_INDENT       => '    ',
  17.                     XML_SERIALIZER_OPTION_LINEBREAKS   => "\n",
  18.                     XML_SERIALIZER_OPTION_DEFAULT_TAG  => array(),
  19.                     XML_SERIALIZER_OPTION_DEFAULT_TAG  => array('foos' => 'foo''bars' => 'bar')
  20.                 );
  21.  
  22. $serializer = new XML_Serializer($options);
  23.  
  24. $data = array(
  25.                 'foos' => array('one foo''two foos''three foos'),
  26.                 'bars' => array('one bar''two bars''three bars'),
  27.             );
  28.  
  29. $result $serializer->serialize($data);
  30.  
  31. if ($result === true{
  32.     echo '<pre>';
  33.     echo htmlentities($serializer->getSerializedData());
  34.     echo '</pre>';
  35. }
  36. ?>

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