在php GET请求中向URl添加变量

时间:2017-02-21 16:30:50

标签: php get

我正在尝试在URL上添加太多变量,以便我发出php GET请求。

   $varible1 = 'bar';
   $variable2 = 'foo';

   curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'https://example.com/<?php echo $variable1 ?>/amount/<?php echo $variable2 ?>,
    CURLOPT_USERAGENT => 'Codular Sample cURL Request'
));

我可以通过文本编辑器的颜色格式看到它是错误的请帮助

2 个答案:

答案 0 :(得分:0)

你应该使用字符串连接(避免因为你似乎在php数组中)

CURLOPT_URL => 'https://example.com/' . $variable1 '/amount/' .  $variable2 ,

答案 1 :(得分:0)

当您使用“而不是”时,您可以轻松插入变量。

例如

CURLOPT_URL => "https://example.com/$variable1/amount/$variable2";