Hi,
I am trying to integrate Google Checkout into my store. When a user completes a transaction google send details in XML format that can then be stored on my database.
I've never dealt with XML before so I've been learning how to use PHP to deal with it.
To test out the data I have been storing it in a PHP array and then using a foreach loop to write the contents to a text file.
The problem comes when Google sends the XML to my file, I get an error when parsing the XML and the data does not get written to the text file.
The error occurs on line 159 of the XML which contains this.
<?xml version="1.0" encoding="UTF-8"?>
This is the PHP code I have been using.
<?php
$blank = fopen("record_details.txt", "a+");
fwrite($blank, $HTTP_RAW_POST_DATA);
$file = $HTTP_RAW_POST_DATA;
global $order_data;
$order_data = array();
$counter = 0;
function contents($parser, $data){
global $counter;
global $order_array;
$order_array[$counter] = $data;
}
function startTag($parser, $data){
global $counter;
}
function endTag($parser, $data){
global $counter;
$counter++;
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "contents");
$fp = fopen($file, "r");
$data = fread($fp, 80000);
if(!(xml_parse($xml_parser, $data, feof($fp)))){
die("Error on line " . xml_get_current_line_number($xml_parser));
}
xml_parser_free($xml_parser);
fclose($fp);
foreach($order_array as $key => $value) {
$store_file = fopen("record_details.txt", "a+");
fwrite($store_file, "KEY = $key VALUE = $value \n");
}
?>
Can anyone give me a pointer as to how I can over come this error?
I hope I've explained this in enough detail.
Thanks for any advice