0

I'm Trying to create DeepL glossaries and found a site that takes cURL and converts it to PHP, the PHP has hard wired data which I need to replace with variables passed to the PHP via POST, how do I replace the hard wired data with the variables, this is my first PHP routine , the code is as follows:

$url = "https://api.deepl.com/v2/glossaries";
$pass_auth_key = $_POST["pass_auth_key"];
$pass_name = $_POST["pass_name"];
$target_lang = $_POST["pass_target_lang"];
$pass_entries = $_POST["pass_entries"];

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$headers = array(
   "Authorization: DeepL-Auth-Key .$pass_auth_key",
   "Content-Type: application/x-www-form-urlencoded",
);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

$data = <<<DATA
name=.$pass_name&source_lang=en&target_lang=.$target_lang&entries=.pass_entries&entries_format=tsv
DATA;

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
?>
Peter
  • 83
  • 9
  • 1
    You don't use `.` to concatenate when you substitute a variable inside a string. Get rid of all of those. – Barmar Jul 21 '22 at 05:15
  • 1
    A life pro tip: when asking next time, omit the unnecessary details. Given your question is about text and variables, then naturally there must be no curl related code in it. A pro move: **verify the intermediate results.** Given you've got your $data - **print it out and inspect the result**, whether it meets your expectations. – Your Common Sense Jul 21 '22 at 05:24
  • Barmar - Works perfect, thanks – Peter Jul 21 '22 at 05:32

0 Answers0