I can get the JSON file from a weather site, using numeric value of latitude and longitude of a location with this code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://weathersite.xyz/complete.json?lat=38.59&lon=-8.43');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
$fIOURL = curl_exec($ch);
curl_close($ch) ;
However, what I really want is to use php variables ($latitude and $longitude) instead of these numeric values in the url, but when I try to replace them it doesn't work. As an example,
$latitude="38.50";
$longitude="-8.43";
....
curl_setopt($ch, CURLOPT_URL,"https://weathersite.xyz/complete.json?lat={$latitude}&lon={longitude}");
....
I also tried all possibilities of single and double quoting the variables in the url like I do in html, but nothing seems to work with curl_setopt. Is there any solution for including php variables inside a url in curl_setopt?