PEAR Unserializer and the &

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
burpy
Forum Newbie
Posts: 2
Joined: Thu Feb 24, 2011 2:35 pm

PEAR Unserializer and the &

Post by burpy »

Hi,

I try to use the PEAR Unserializer (http://pear.php.net/manual/en/package.x ... alizer.php) to convert XML into an array. It works fine but the & disapears (see below). Does anyone know why? I will not work with an other tool because it works fine in a large system.

Thanks a lot!
burpy

Code: Select all

<?php
require('XML/Unserializer.php');

$unserializer_options = array (
	'mode' => 'simplexml',
	'scalarAsAttributes' => false,
	'attributesArray' => '_attributes',
	'contentName' => '_content',
	'targetEncoding' => 'iso-8859-1',
	'parseAttributes' => true);

$XML_unserializer = &new XML_Unserializer($unserializer_options);


$xml = '<?xml version="1.0" encoding="iso-8859-1" ?>
<product>
<name>Abercrombie & Fitch</name>
</product>';

//Unserialize the XML data structure
$products = $XML_unserializer->unserialize($xml, false);

//Check whether unserialization of XML worked
if(PEAR::isError($products)){
die($products->getMessage());
}

//Get unserialized data
$feed = $XML_unserializer->getUnserializedData();

echo "<pre>";
print_r($feed);
echo "</pre>";

User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: PEAR Unserializer and the &amp;

Post by Weirdan »

Post the output of this script, but please use

Code: Select all

echo htmlspecialchars(var_export($feed, true));
instead of print_r()
burpy
Forum Newbie
Posts: 2
Joined: Thu Feb 24, 2011 2:35 pm

Re: PEAR Unserializer and the &amp;

Post by burpy »

no this doesn't help. The output is the same:
array (
'name' => 'Abercrombie Fitch',
)

The & disappears!
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: PEAR Unserializer and the &amp;

Post by Weirdan »

http://pear.php.net/bugs/bug.php?id=16153 - seems to be exactly your issue
Post Reply