1
the code is complete I believe but I do not know work with json
, I just need to get the results from the other days that I can only get from today’s code:
$chave = 'fdhfju35'; // Obtenha sua chave de API gratuitamente em http://hgbrasil.com/weather
// Resgata o IP do usuário
$ip = $_SERVER["REMOTE_ADDR"];
function hg_request($parametros, $chave = null, $endpoint = 'weather'){
$url = 'http://api.hgbrasil.com/'.$endpoint.'/?format=json&';
if(is_array($parametros)){
// Insere a chave nos parametros
if(!empty($chave)) $parametros = array_merge($parametros, array('key' => $chave));
// Transforma os parametros em URL
foreach($parametros as $key => $value){
if(empty($value)) continue;
$url .= $key.'='.urlencode($value).'&';
}
// Obtem os dados da API
$resposta = file_get_contents(substr($url, 0, -1));
return json_decode($resposta, true);
} else {
return false;
}
}
$dados = hg_request(array(
'user_ip' => $ip
), $chave);
function imagem($valor){
$pontos = array("n");
$result = str_replace($pontos, "", $valor);
return $result;
}
With this code I can get the temperature for today but the other days as I do?
$dados['results']['temp']
and in charge json
provides the other days just don’t know how to pick up:
http://api.hgbrasil.com/weather?format=json&
You want to list every day ? You will have to trace a repetitive loop there.
– Mauro Alexandre