-1

I have that Curl command works fine

$ch = curl_init('http://api.pushingbox.com/pushingbox?devid=vB9C6311111098CB&sensor=DELTA&temperature=23');
curl_exec ($ch);

curl_close ($ch);

But I need to change the values "DELTA" and "23" with PHP variables $sensor and $temperature.

My question is: How to insert the variables $sensor and $temperature inside the Curl command?

Donald Duck
  • 8,409
  • 22
  • 75
  • 99

2 Answers2

1

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);
henrique
  • 1,072
  • 10
  • 17
1

Your CURL command is a string. 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.

TecBrat
  • 3,643
  • 3
  • 28
  • 45