|
Server : Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 System : Linux server.jackjohnson.com 2.6.32-279.5.2.el6.x86_64 #1 SMP Fri Aug 24 01:07:11 UTC 2012 x86_64 User : jackjohn ( 502) PHP Version : 5.3.17 Disable Function : NONE Directory : /usr/share/doc/cpanel-php54-XML-Serializer-0.20.2/examples/ |
Upload File : |
<?PHP
/**
* This example shows how to set a different target encoding
*
* @author Stephan Schmidt <schst@php.net>
*/
error_reporting(E_ALL);
require_once 'XML/Unserializer.php';
$xml = '<xml>
<string>
This XML
document
contains
line breaks.
</string>
</xml>';
// be careful to always use the ampersand in front of the new operator
$unserializer = &new XML_Unserializer();
$unserializer->setOption(XML_UNSERIALIZER_OPTION_RETURN_RESULT, true);
echo '<pre>';
echo "Default behavior (XML_UNSERIALIZER_WHITESPACE_TRIM)\n";
$data = $unserializer->unserialize($xml);
var_dump($data);
echo "\n\n";
echo "Normalize whitespace (XML_UNSERIALIZER_WHITESPACE_NORMALIZE)\n";
$unserializer->setOption(XML_UNSERIALIZER_OPTION_WHITESPACE, XML_UNSERIALIZER_WHITESPACE_NORMALIZE);
$data = $unserializer->unserialize($xml);
var_dump($data);
echo "\n\n";
echo "Keep whitespace (XML_UNSERIALIZER_WHITESPACE_KEEP)\n";
$unserializer->setOption(XML_UNSERIALIZER_OPTION_WHITESPACE, XML_UNSERIALIZER_WHITESPACE_KEEP);
$data = $unserializer->unserialize($xml);
var_dump($data);
echo '</pre>';
?>