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

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