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

Source for file serializeAndEncode.php

Documentation is available at serializeAndEncode.php

  1. <?PHP
  2. /**
  3.  * Example to demonstrate the encodeFunction and decodeFunction
  4.  * options.
  5.  *
  6.  * This allows you to apply callbacks to your data that is called
  7.  * on all strings while serializing and unserializing.
  8.  *
  9.  * @author Stephan Schmidt <schst@php.net>
  10.  */
  11.     error_reporting(E_ALL);
  12.  
  13.     require_once 'XML/Serializer.php';
  14.     require_once 'XML/Unserializer.php';
  15.  
  16.     // this is just to get a nested object
  17.     $pearError = PEAR::raiseError('This is just an error object',123);
  18.     
  19.     $options = array(
  20.                         'indent'             => '    ',
  21.                         'linebreak'          => "\n",
  22.                         'scalarAsAttributes' => true,
  23.                         'encodeFunction'     => 'strtoupper'
  24.                     );
  25.     
  26.     $foo = new stdClass();
  27.     $foo->bar = new stdClass();
  28.     $foo->bar->test = 'This is a test.';
  29.     $foo->bar->value = 'This is a value.';
  30.     
  31.     $serializer &new XML_Serializer($options);
  32.     
  33.     $result $serializer->serialize($foo);
  34.     
  35.     if$result === true {
  36.         $xml $serializer->getSerializedData();
  37.     }
  38.  
  39.     echo    "<pre>";
  40.     print_rhtmlspecialchars($xml) );
  41.     echo    "</pre>";
  42.  
  43.     $unserializer &new XML_Unserializer();
  44.     $unserializer->setOption('parseAttributes'true);
  45.     $unserializer->setOption('decodeFunction''strtolower');
  46.  
  47.     $result $unserializer->unserialize($xml);
  48.     
  49.     echo '<pre>';
  50.     print_r($unserializer->getUnserializedData());
  51.     echo '</pre>';
  52. ?>

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