'I can write Php string in json but not working
My code working. But if add get url and string not working. I want use php variable in json.
My proplem this not working :
$nam = $nam = $_GET['tracknumber'];
"TrackingNumber": "echo json_encode($nam);"
It works when I write the normal cargo number in front of the Track Number. But it does not work when I write a PHP variable.
$nam = $_GET['tracknumber'];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://onlinetools.ups.com/ship/v1/shipments/labels',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"LabelRecoveryRequest": {
"LabelSpecification": {
"HTTPUserAgent": "",
"LabelImageFormat": {
"Code": "GIF"
}
},
"LabelDelivery": {
"LabelLinkIndicator": "",
"ResendEMailIndicator": "",
"EMailMessage": {
"EMailAddress": ""
}
},
"TrackingNumber": "echo json_encode($nam);"
}
}',
CURLOPT_HTTPHEADER => array(
'Username: xxxxx',
'Password: xxxxx',
'AccessLicenseNumber: xxxxxxx',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
preg_match_all('@"GraphicImage":"(.*?)",@', $response, $veri);
echo "<img src=data:image/jpeg;base64,".$veri[1][0].">";
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
