在此PHP命令中添加一个变量

时间:2016-12-22 19:22:25

标签: php

我目前在我的php文件中有这个:

$output = shell_exec('curl --anyauth --location-trusted -u: -c cookies.txt -b cookies.txt -v -k "https://someurl.com/search?term=11111111&warehouseId=123" >> log.txt');

我需要在url中放一个变量,看起来像:

https://someurl.com/search?term=$VARIABLEGOESHERE&warehouseId=123

语法会是什么样的?

2 个答案:

答案 0 :(得分:2)

@Abhishek是对的,但这里可能会有一些解释/术语。

您正在寻找的功能一般称为'字符串插值'虽然php文档将其称为'变量解析'。扫描大约四分之一的时间:http://php.net/manual/en/language.types.string.php

并使用如下:

$value = 'dog';
$string = "the lazy brown $value";
echo $string;

回音将显示the lazy brown dog

请注意,要使插值工作,$ string必须是双引号。如果我们有:

$string = 'the lazy brown $value'
echo $string;

回音将显示the lazy brown $value

答案 1 :(得分:0)

$VARIABLEGOESHERE = "111111";
$output = shell_exec("curl --anyauth --location-trusted -u: -c cookies.txt -b cookies.txt -v -k \"https://someurl.com/search?term=$VARIABLEGOESHERE&warehouseId=123\" >> log.txt");
相关问题