如何在php中动态更改变量

时间:2016-10-02 15:06:18

标签: php

我有一个特定ID号的令牌,即494

$url = api.pipedrive.com/v1/deals/494/products?start=0&api_token=7ecb71622dadd2faae2732bfe73b09381150c967;

我想将数字494更改为任意数字。

我开始制作一个不合逻辑的代码。

有关如何执行此操作的任何指南?

$url = "https://api.pipedrive.com/v1/deals/";
$id = 494;
$api = "/products?start=0&api_token=7ecb71622dadd2faae2732bfe73b09381150c967";

$response = file_get_contents($url+$id+$api);
echo $response;

$object = json_decode($response, true);

我收到了错误

  

警告:file_get_contents(494):无法打开流:没有此类文件   或目录

2 个答案:

答案 0 :(得分:2)

您正在使用“+”运算符进行连接。其中两个变量相加。 您需要使用连接运算符('。')而非'+'

$url = $url.$id.$api;

答案 1 :(得分:0)

在PHP中,.用于字符串连接。您还可以使用.=将字符串附加到字符串变量。例如:

$str = "Hello";
$str2 = $str . "Anthea"; // $str2 = "Hello Anthea"

或者

$str = "Hello";
$str .= "Anthea"; // $str = "Hello Anthea"
相关问题