There is a problem in parsing the XML.
I tried the following code (using some code from http://php.net/manual/en/function.libxml-get-errors.php):
<?php
libxml_use_internal_errors(true);
$string = $_POST['results'];
$loaded_xml = simplexml_load_string($string);
$xml = explode("\n", $string);
$errors = libxml_get_errors();
foreach ($errors as $error) {
echo display_xml_error($error, $xml);
}
foreach ($loaded_xml->receipt as $value) {
print_r($value);
}
function display_xml_error($error, $xml)
{
$return = $xml[$error->line - 1] . "\n";
$return .= str_repeat('-', $error->column) . "^\n";
switch ($error->level) {
case LIBXML_ERR_WARNING:
$return .= "Warning $error->code: ";
break;
case LIBXML_ERR_ERROR:
$return .= "Error $error->code: ";
break;
case LIBXML_ERR_FATAL:
$return .= "Fatal Error $error->code: ";
break;
}
$return .= trim($error->message) .
"\n Line: $error->line" .
"\n Column: $error->column";
if ($error->file) {
$return .= "\n File: $error->file";
}
return "$return\n\n--------------------------------------------\n\n";
}
And I got many errors. Here are the first two:
<?xml version=\"1.0\" encoding=\"utf-8\"?> <root> <receipt status=\"1\" id=\"PAR/2\" idreceipt=\"1\" date=\"YYMMDD\" errorstr=\"\" /> <receipt status=\"1\" id=\"PAR/2/2\" idreceipt=\"2\" date=\"YYYY-MM-DD HH:II:SS\" errorstr=\"\" /> <receipt status=\"0\" id=\"PAR/2/3\" idreceipt=\"3\" date=\"YYYY-MM-DD HH:II:SS\" errorstr=\"ERROR\" /> </root>
--------------^
Fatal Error 33: String not started expecting ' or "
Line: 1
Column: 14
--------------------------------------------
<?xml version=\"1.0\" encoding=\"utf-8\"?> <root> <receipt status=\"1\" id=\"PAR/2\" idreceipt=\"1\" date=\"YYMMDD\" errorstr=\"\" /> <receipt status=\"1\" id=\"PAR/2/2\" idreceipt=\"2\" date=\"YYYY-MM-DD HH:II:SS\" errorstr=\"\" /> <receipt status=\"0\" id=\"PAR/2/3\" idreceipt=\"3\" date=\"YYYY-MM-DD HH:II:SS\" errorstr=\"ERROR\" /> </root>
--------------^
Fatal Error 96: Malformed declaration expecting version
Line: 1
Column: 14
--------------------------------------------
Now, according to this post, This is probably caused by magic_quotes_runtime adding backslashes when you ... .
So, I think this will solve your problem:
<?php
libxml_use_internal_errors(true);
$string = $_POST['results'];
$string = stripslashes($string);
$loaded_xml = simplexml_load_string($string);
// rest of the code is the same as above