我正在尝试运行一个shell命令里面的php代码。
我的shell命令是这样的:
curl -X POST "https://supergoodwebsite.com/v2/SOMENUMBERS/supplement.json" \
-H "Api-Key:RGNROK-H219R32" \
-i \
-H "Content-Type: specification/json" \
-d \
'{
"deployment": {
"revision": "REVISION",
"changelog": "",
"description": "Some Description",
"user": "MasterUser"
}
}'
我试图在**PHP shell_exec()**命令中运行它。
我对引用有很多问题。我试过的是:
<?php
$APP_ID = 38993011;
$DESCRIPTION = "deneme";
$USER = "superuser";
$CMD = 'curl -X POST "https://superwebsite/v2/"$APP_ID"/supplements.json" \
-H "Api-Key:SAAK-EJRV2PDLKGES0L7NTT" \
-i \
-H "Content-Type: specification/json" \
-d \
'{
"deployment": {
"revision": "REVISION",
"changelog": "",
"description": '"$DESCRIPTION"',
"user": '"$USER"'
}
}'
';
$output = shell_exec($CMD);
print($output);
?>
1条答案
按热度按时间u5i3ibmn1#
当一个变量包含的引号(
"
或'
)与你用来打开和关闭它的引号相同时,你需要使用\
来转义里面的引号。