Hirdetés

Új hozzászólás Aktív témák

  • sqpp

    őstag

    <?php
    $city="Budapest"; // Your city
    $country="hu"; // Two digit country code
    $url="http://api.openweathermap.org/data/2.5/weather?q=".$city.",".$country."&appid=2de143494c0b295cca9337e1e96b00e0&units=metric";
    $json=file_get_contents($url);
    $data=json_decode($json,true);
    $file = '/home/cs2d/sys/lua/weather.dat';
    $current = file_get_contents($file);
    $current .= $data['weather'][0]['main']."\n".$data['main']['temp']."\n";
    // Write the contents back to the file
    $lines = file($current, FILE_IGNORE_NEW_LINES);
    $remove = $current;
    foreach($lines as $key => $line)
    if(stristr($line, $remove)) unset($lines[$key]);

    $data = implode('\n', array_values($lines));

    $file = fopen($path);
    fwrite($file, $data);
    fclose($file);

    ?>

    Ötlet, hogy mi a gond? A cél az lenne, hogy az adott értéket az időjárásról elmenti a fájlba, de nem új sorba kezdi azt, hanem csak frissíti, viszont nem akar működni úgy, ahogy kéne :(

Új hozzászólás Aktív témák