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

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