I'm really sorry if I'm frustrating you, I'm trying to figure this out and I appreciate your input.
I've tried replacing what I have with the code from your previous post but I'm just getting the region names and nothing else. I'm unsure as to whether I need to totally scrap the XMLreader you posted first of all.
I'll post my code which works at the moment, if you could advise me where to change it that would help, otherwise I understand if you'd rather just virtually punch me in the face and let me work it out for myself.
<?php
error_reporting(E_ALL); // Turn on all errors, warnings, and notices for easier debugging
$endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1'; // URL to call
$reader = new XMLReader();
$reader->open('config.xml');
while ($reader->read()) {
if($reader->nodeType == XMLREADER::ELEMENT){
if ($reader->name == "name"){
$reader->read();
$name = trim($reader->value);
}elseif($reader->name == "region"){
$reader->read();
$region = trim($reader->value);
}
if(!empty($name) && !empty($region)){
$city_array[] = "'$name, $region'";
$name="";$region="";
}
}
}
$query = implode(', ', $city_array);
// Create a PHP array of the item filters you want to use in your request
$filterarray =
array(
array(
'name' => 'MaxPrice',
'value' => '25',
'paramName' => 'Currency',
'paramValue' => 'GBP'),
array(
'name' => 'FreeShippingOnly',
'value' => 'true',
'paramName' => '',
'paramValue' => ''),
array(
'name' => 'ListingType',
'value' => array('AuctionWithBIN','FixedPrice','StoreInventory'),
'paramName' => '',
'paramValue' => ''),
);
// Generates an XML snippet from the array of item filters
function buildXMLFilter ($filterarray) {
global $xmlfilter;
// Iterate through each filter in the array
foreach ($filterarray as $itemfilter) {
$xmlfilter .= "<itemFilter>\n";
// Iterate through each key in the filter
foreach($itemfilter as $key => $value) {
if(is_array($value)) {
// If value is an array, iterate through each array value
foreach($value as $arrayval) {
$xmlfilter .= " <$key>$arrayval</$key>\n";
}
}
else {
if($value != "") {
$xmlfilter .= " <$key>$value</$key>\n";
}
}
}
$xmlfilter .= "</itemFilter>\n";
}
return "$xmlfilter";
} // End of buildXMLFilter function
// Build the item filter XML code
buildXMLFilter($filterarray);
// Construct the findItemsByKeywords POST call
// Load the call and capture the response returned by the eBay API
// the constructCallAndGetResponse function is defined below
$resp = simplexml_load_string(constructPostCallAndGetResponse($endpoint, $query, $xmlfilter));
// Check to see if the call was successful, else print an error
if ($resp->ack == "Success") {
$results = ''; // Initialize the $results variable
// Parse the desired information from the response
foreach($resp->searchResult->item as $item) {
$pic = $item->galleryURL;
$link = $item->viewItemURL;
$title = $item->title;
// Build the desired HTML code for each searchResult.item node and append it to $results
$results .= "<tr><td><img src=\"$pic\"></td><td><a href=\"$link\">$title</a></td></tr>";
}
}
else { // If the response does not indicate 'Success,' print an error
$results = "<h3>Oops! The request was not successful. Make sure you are using a valid ";
$results .= "AppID for the Production environment.</h3>";
}
?>
<!-- Build the HTML page with values from the call response -->
<html>
<head>
<title>eBay Search Results for <?php echo $query; ?></title>
<style type="text/css">body {font-family: arial, sans-serif;} </style>
</head>
<body>
<h1>eBay Search Results for <?php echo $query; ?></h1>
<table>
<tr>
<td>
<?php echo $results;?>
</td>
</tr>
</table>
</body>
</html>
<?php
function constructPostCallAndGetResponse($endpoint, $query, $xmlfilter) {
global $xmlrequest;
// Create the XML request to be POSTed
$xmlrequest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$xmlrequest .= "<findItemsByKeywordsRequest xmlns=\"http://www.ebay.com/marketplace/search/v1/services\">\n";
$xmlrequest .= "<keywords>";
$xmlrequest .= $query;
$xmlrequest .= "</keywords>\n";
$xmlrequest .= $xmlfilter;
$xmlrequest .= "<paginationInput>\n <entriesPerPage>3</entriesPerPage>\n</paginationInput>\n";
$xmlrequest .= "</findItemsByKeywordsRequest>";
// Set up the HTTP headers
$headers = array(
'X-EBAY-SOA-OPERATION-NAME: findItemsByKeywords',
'X-EBAY-SOA-SERVICE-VERSION: 1.3.0',
'X-EBAY-SOA-REQUEST-DATA-FORMAT: XML',
'X-EBAY-SOA-GLOBAL-ID: EBAY-GB',
'X-EBAY-SOA-SECURITY-APPNAME: *hidden*',
'Content-Type: text/xml;charset=utf-8',
);
$session = curl_init($endpoint); // create a curl session
curl_setopt($session, CURLOPT_POST, true); // POST request type
curl_setopt($session, CURLOPT_HTTPHEADER, $headers); // set headers using $headers array
curl_setopt($session, CURLOPT_POSTFIELDS, $xmlrequest); // set the body of the POST
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // return values as a string, not to std out
$responsexml = curl_exec($session); // send the request
curl_close($session); // close the session
return $responsexml; // returns a string
} // End of constructPostCallAndGetResponse function
?>
XML (only displays results when just 1 city is used) -
<?xml version="1.0"?>
<config version="1.0">
<city id="0">
<name>Oxford</name>
<region>Oxfordshire</region>
<country>United Kingdom</country>
<weather>http://www.google.com/ig/api?weather=Oxford+GB</weather>
<news>http://feeds.bbci.co.uk/news/england/oxford/rss.xml</news>
<map>
<lat>51.751944</lat>
<long>-1.257778</long>
<scale>3000</scale>
</map>
</city>
</config>