PHP变量作为URL中的参数
|
我想创建一个天气预报器,以按访客的IP显示天气预报。
我正在尝试将变量$ ip放置到URL中,但是它不起作用。当我放置真实IP而不是$ ip时。有用。
我究竟做错了什么?
$ip=$_SERVER[\'REMOTE_ADDR\'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, \"http://free.worldweatheronline.com/feed/weather.ashx?key=xxxxxxxxxxxxxxx&q=.$ip.&localObsTime&num_of_days=5&format=json\");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$outputJson = curl_exec($ch);
if ($outputJson === FALSE) {
echo \'Error: \'.curl_error($ch);
}
echo \'<pre> \';
print_r($outputJson);
echo \'</pre> \';
没有找到相关结果
已邀请:
4 个回复
娠频摩
之前和之后有一些不必要的点: 使用以下任何一项:
bab
辰炔诚薯
在网址中。
驮帽俺篮号
要么