Ali Ali - 3 months ago 8
PHP Question

PHP variable not concatenating correctly

My

$app_id
variable is not concatenating correctly in the
$URL
variable.

$result = $_GET;

$app_id = $result["appid"];

$KeyWord = test_input($return["keyword"]);

$URL ="http://svcs.ebay.com/services/search/FindingService/v1?siteid=0&SECURITY-APPNAME=. $app_id . &OPERATION-NAME=findItemsAdvanced&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=XML&keywords=";

$URL=$URL.$KeyWord.$app_id."&paginationInput.entriesPerPage=".$NumPerPage."&paginationInput.pageNumber=".$pageNumber."&sortOrder=".$sortOrder.$condition.$minPrice.$maxPrice.$buyingFormat.$seller.$FreeShippingOnly.$ExpeditedShippingType.$MaxHandlingTime.$SellerInfo.$PictureURLSuperSize.$StoreInfo;//


I cannot figure it out. How do I concatenate my variable properly?

Answer

You don't concatenate in quotes. You can use curly braces so variable names are easier to see (and PHP knows where the variable ends).

$URL ="http://svcs.ebay.com/services/search/FindingService/v1?siteid=0&SECURITY-APPNAME={$app_id}&OPERATION-NAME=findItemsAdvanced&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=XML&keywords=";

or you can break the quotes and concatenate.

$URL ="http://svcs.ebay.com/services/search/FindingService/v1?siteid=0&SECURITY-APPNAME=" . $app_id . "&OPERATION-NAME=findItemsAdvanced&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=XML&keywords=";