HEX
Server: Apache
System: Linux sg241.singhost.net 2.6.32-896.16.1.lve1.4.51.el6.x86_64 #1 SMP Wed Jan 17 13:19:23 EST 2018 x86_64
User: honghock (909)
PHP: 8.0.30
Disabled: passthru,system,shell_exec,show_source,exec,popen,proc_open
Upload Files
File: //opt/alt/php54/usr/share/doc/pear/XML_Serializer/examples/unserializeWithTypeGuessing.php
<?PHP
/**
 * Example that shows how to use XML_Unserializer to
 * automatically adjust the type of the data
 *
 * @author      Stephan Schmidt <schst@php.net>
 * @category    XML
 * @package     XML_Serializer
 * @subpackage  Examples
 */
error_reporting(E_ALL);

/**
 * uses XML_Unserializer
 */
require_once '../Unserializer.php';

$xml = <<<EOT
<root>
   <string>Just a string...</string>
   <booleanValue>true</booleanValue>
   <foo>-563</foo>
   <bar>4.73736</bar>
   <array foo="false" bar="12">true</array>
</root>
EOT;

$unserializer = &new XML_Unserializer();
$unserializer->setOption(XML_UNSERIALIZER_OPTION_COMPLEXTYPE, 'array');
$unserializer->setOption(XML_UNSERIALIZER_OPTION_ATTRIBUTES_PARSE, true);
$unserializer->setOption(XML_UNSERIALIZER_OPTION_RETURN_RESULT, true);
$unserializer->setOption(XML_UNSERIALIZER_OPTION_GUESS_TYPES, true);

$data = $unserializer->unserialize($xml);    
echo '<pre>';
var_dump($data);
echo '</pre>';
?>