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

Source for file serializeIndexedArray.php

Documentation is available at serializeIndexedArray.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_ROOT_NAME    => 'rdf:RDF',
  20.                         XML_SERIALIZER_OPTION_ROOT_ATTRIBS => array('version' => '0.91'),
  21.                         XML_SERIALIZER_OPTION_MODE         => XML_SERIALIZER_MODE_SIMPLEXML
  22.                     );
  23.     
  24.     $serializer = new XML_Serializer($options);
  25.  
  26.     
  27.     $rdf = array(
  28.                 'channel' => array(
  29.                                     'title' => 'Example RDF channel',
  30.                                     'link'  => 'http://www.php-tools.de',
  31.                                     'image'    =>    array(
  32.                                                         'title'    => 'Example image',
  33.                                                         'url'    =>    'http://www.php-tools.de/image.gif',
  34.                                                         'link'    =>    'http://www.php-tools.de'
  35.                                                     ),
  36.                                     'item'   =>  array(
  37.                                                         array(
  38.                                                             'title'    => 'Example item',
  39.                                                             'link'    => 'http://example.com'
  40.                                                         ),
  41.                                                         array(
  42.                                                             'title'    => 'Another item',
  43.                                                             'link'    => 'http://example.com'
  44.                                                         ),
  45.                                                         array(
  46.                                                             'title'    => 'I think you get it...',
  47.                                                             'link'    => 'http://example.com'
  48.                                                         )
  49.                                                       )
  50.                                 )
  51.                     );
  52.     
  53.     $result $serializer->serialize($rdf);
  54.     
  55.     if$result === true {
  56.         echo    '<pre>';
  57.         echo    htmlentities($serializer->getSerializedData());
  58.         echo    '</pre>';
  59.     }
  60. ?>

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