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

Source for file serializeArrayWithObjects.php

Documentation is available at serializeArrayWithObjects.php

  1. <?PHP
  2. /**
  3.  * This example shows how to create an RDF document
  4.  * with a few lines of code.
  5.  * This can also be done with mode => simplexml
  6.  *
  7.  * @author Stephan Schmidt <schst@php.net>
  8.  * @see    serializeIndexedArray.php
  9.  */
  10.     error_reporting(E_ALL);
  11.  
  12.     require_once 'XML/Serializer.php';
  13.  
  14.     $options = array(
  15.                         "indent"          => "    ",
  16.                         "linebreak"       => "\n",
  17.                         "typeHints"       => false,
  18.                         "addDecl"         => true,
  19.                         "encoding"        => "UTF-8"
  20.                     );
  21.     
  22.     $serializer = new XML_Serializer($options);
  23.  
  24.     $serializer->setErrorHandling(PEAR_ERROR_DIE);
  25.     
  26.     $array = array(
  27.                     new stdClass(),
  28.                     new stdClass()
  29.                     );
  30.     
  31.     $result $serializer->serialize($array);
  32.     
  33.     if$result === true {
  34.         echo    "<pre>";
  35.         echo    htmlentities($serializer->getSerializedData());
  36.         echo    "</pre>";
  37.     }
  38.  
  39.     $result $serializer->serialize($arrayarray'classAsTagName' => true ));
  40.     
  41.     if$result === true {
  42.         echo    "<pre>";
  43.         echo    htmlentities($serializer->getSerializedData());
  44.         echo    "</pre>";
  45.     }
  46.     
  47. ?>

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