This is my error:
error on line 2 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.
I just copied the code from here.
Here’s my code:
<?php
header('Content-type: text/xml');
function awsRequest($searchIndex, $keywords, $responseGroup = false, $operation = "ItemSearch", $pageNumber = 1){
$service_url = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService";
$associate_tag = "your-associate-tag";
$secret_key = "YOUR_SECRET_KEY";
$access_key = "YOUR_ACCESS_KEY";
// build initial request uri
$request = "$service_url&Operation=$operation&AssociateTag=$associate_tag&SearchIndex=$searchIndex&Keywords=".urlencode($keywords)."&ItemPage=$pageNumber";
// parse request into params
$uri_elements = parse_url($request);
$request = $uri_elements['query'];
parse_str($request, $parameters);
// add new params
$parameters['Timestamp'] = gmdate("Y-m-d\TH:i:s\Z");
$parameters['Version'] = $version;
$parameters['AWSAccessKeyId'] = $access_key;
if($responseGroup){
$parameters['ResponseGroup'] = $responseGroup;
}
ksort($parameters);
// encode params and values
foreach($parameters as $parameter => $value){
$parameter = str_replace("%7E", "~", rawurlencode($parameter));
$value = str_replace("%7E", "~", rawurlencode($value));
$request_array[] = $parameter . '=' . $value;
}
$new_request = implode('&', $request_array);
// make it happen
$signature_string = "GET\n{$uri_elements['host']}\n{$uri_elements['path']}\n{$new_request}";
$signature = urlencode(base64_encode(hash_hmac('sha256', $signature_string, $secret_key, true)));
// return signed request uri
return "http://{$uri_elements['host']}{$uri_elements['path']}?{$new_request}&Signature={$signature}";
}
// make the request
$xml = simplexml_load_file(awsRequest("VideoGames", "call of duty", "Images", "ItemSearch", "1"));
// now retrieve some data
$totalPages = $xml->Items->TotalPages;
echo "<p>There are $totalPages pages in the XML results.</p>";
// retrieve data in a loop
echo "<ul>\n";
foreach($xml->Items->Item as $item){
echo "<li>".$item->ASIN."</li>\n";
}
echo "</ul>\n";
?>
I’m deploying this on AWS.
Make sure that your code editor doesn’t include a BOM in the document. I know for a fact that notepad++ and some others include this by default. If it is included, it will insert invisible characters into your document, which looks like output to the server, causing the error messages you’re seeing. Try copying and pasting your code into a NEW document that does not have the BOM.
Creating a new php document in Dreamweaver (or other editor) WITHOUT the BOM (byte order mark) should solve the issue.