-1
Guys I have the following code:
<?php
$key = "*****************";
$forcast_days='5';
$city = '-30.1087957,-51.3169879';
$url ="http://api.apixu.com/v1/forecast.json?key=$key&q=$city&days=$forcast_days&=";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$json_output=curl_exec($ch);
$weather = json_decode($json_output);
$days = $weather->forecast->forecastday;
echo "Cidade: ". $weather->location->name;
echo "<br>";
echo "Estado: ".$weather->location->region;
echo "<br>";
echo "Pais: ".$weather->location->country;
foreach ($days as $day){
echo "<table>";
echo "<tr><td colspan='4' border='0'><h2>{$day->date}</h2>";
echo "<tr><td><h4>Wind</h4></td><td colspan='3'>{$day->day->maxwind_mph}Mph <br> {$day->day->maxwind_kph}kph </td></tr>";
foreach ($day->hour as $hr){
echo "<tr><td colspan='4' border='0'>";
echo "<table style='width:100%;'>";
echo "<tr><td>Time</td><td>Temprature</td><td>Wind</td><td>Humidity</td></tr>";
echo "<tr><td><div>{$hr->time}<img src=' {$hr->condition->icon}'/></div></td><td>{$hr->temp_c}°C<br>{$hr->temp_f}°F</td><td>{$hr->wind_mph}Mph <br> {$hr->wind_kph}kph</td><td>$hr->humidity</td></tr>";
echo "</table></tr></td>";
}
echo "</table> <br>";
Here is the result on the web: http://ioenergias.com.br/climapesca
How I can select variables, for example, from 00:00 to 06:00 only?
You can put an example of the pure json you receive sff?
– Miguel
JSON is not offered. But you have the API Docs page: https://www.apixu.com/doc/forecast.aspx
– GustavoCave
I’m trying to use some kind of if, for when the time between 00:00 and 06:00 it return the information, more so far without success.
– GustavoCave
@Gustavocave just give one
echo
orvar_dump
in the$json_output
for you to see what was returned. Then you can post here to be helped.– Leonardo
Friend, we need the JSON return even to be able to help you better. But as a hint, I would make this page in Javascript and html. Easier to handle converted JSON array in Javascript.
– Mário César
I tried var_dump(json_decode($json_output, true)); and it returns NULL
– GustavoCave