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

Source for file serializeNullProperties.php

Documentation is available at serializeNullProperties.php

  1. <?PHP
  2. /**
  3.  * This example demonstrates the use of
  4.  * ignoreNull => true
  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.                         "indent"         => '    ',
  18.                         "linebreak"      => "\n",
  19.                     );
  20.     
  21.     $serializer = new XML_Serializer($options);
  22.     
  23.     $object = new stdClass();
  24.     $object->foo = 'bar';
  25.     $object->bar = null;
  26.     
  27.     $array = array(
  28.                     'foo' => 'bar',
  29.                     'bar' => null
  30.                 );
  31.     
  32.     $result $serializer->serialize($object);
  33.     
  34.     if$result === true {
  35.         echo    "<pre>";
  36.         echo    htmlentities($serializer->getSerializedData());
  37.         echo    "</pre>";
  38.     }
  39.  
  40.     $result $serializer->serialize($array);
  41.     
  42.     if$result === true {
  43.         echo    "<pre>";
  44.         echo    htmlentities($serializer->getSerializedData());
  45.         echo    "</pre>";
  46.     }
  47.     
  48.     $serializer->setOption('ignoreNull'true);
  49.     $result $serializer->serialize($object);
  50.     
  51.     if$result === true {
  52.         echo    "<pre>";
  53.         echo    htmlentities($serializer->getSerializedData());
  54.         echo    "</pre>";
  55.     }
  56.     
  57.     $result $serializer->serialize($array);
  58.     
  59.     if$result === true {
  60.         echo    "<pre>";
  61.         echo    htmlentities($serializer->getSerializedData());
  62.         echo    "</pre>";
  63.     }
  64. ?>

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