[英]Insert a PHP variable inside Curl
I have that Curl command works fine我有 Curl 命令工作正常
$ch = curl_init('http://api.pushingbox.com/pushingbox?devid=vB9C6311111098CB&sensor=DELTA&temperature=23');
curl_exec ($ch);
curl_close ($ch);
But I need change de fix values DELTA and 23 to follow php variables但我需要更改 de fix 值 DELTA 和 23 以跟随 php 变量
$sensor $temperature $sensor $温度
My question is: How insert the variables $sensor and $temperature inside Curl command?我的问题是:如何在 Curl 命令中插入变量 $sensor 和 $temperature ?
Thanks谢谢
You can simply concatenate those values like:您可以简单地连接这些值,例如:
$delta = "your value";
$temp = 23;
$url = 'http://api.pushingbox.com/pushingbox?devid=vB9C6311111098CB&sensor=' . $delta . '&temperature=' . $temp;
// or
// $url = "http://api.pushingbox.com/pushingbox?devid=vB9C6311111098CB&sensor=$delta&temperature=$temp";
$ch = curl_init($url);
curl_exec ($ch);
curl_close ($ch);
Your CURL command is a string.您的 CURL 命令是一个字符串。 There are several ways to parse variables into a string.有几种方法可以将变量解析为字符串。
Using Double Quotes:使用双引号:
$ch = curl_init("http://api.pushingbox.com/pushingbox?devid=vB9C6311111098CB&sensor=$sensor&temperature=$temperature");
and和
Concatentation:串联:
$ch = curl_init('http://api.pushingbox.com/pushingbox?devid=vB9C6311111098CB&sensor='.$sensor.'&temperature='.$temperature);
Are probably the most common.可能是最常见的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.