【问题标题】:How to append a value to the end of a url?如何将值附加到 url 的末尾?
【发布时间】:2018-06-25 23:53:24
【问题描述】:

我的代码是

$data = array('promoCode' => $_POST["00"]);
$data_string = json_encode($data);
$url="http://website.com/promotions/(here)" . $name;
$auth_code = $_POST["auth"];
$name = $_POST["voucher"];
$ch = curl_init();  ;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_POST, count($data_string));
curl_setopt($ch, CURLOPT_POSTFIELDS, ($data_string));   
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                                        'Authorization:  ' . $auth_code,
                                        'Connection: close'
                                     ));    

我想在http://website.com/promotions/的斜杠/之后添加字符串

我需要像 $name = $_POST["voucher"]; 一样添加它以将其与 html 输入连接。

【问题讨论】:

    标签: php string curl post concatenation


    【解决方案1】:

    您在声明之前尝试使用$name 变量。将您的 $name 声明重新定位到您的 $url 声明之前,如下所示:

    $name = $_POST["voucher"];
    $url="http://website.com/promotions/" . $name;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-10
      • 2015-03-13
      • 2017-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多