PHP code example of davidwofford / phpdarksky

1. Go to this page and download the library: Download davidwofford/phpdarksky library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

davidwofford / phpdarksky example snippets


    

    $darkSky = new PhpDarkSky('[API KEY]', '[LATITUDE]', '[LONGITUDE]');
    
    try {
        $foreacast = $darkSky->getForecast();
    } catch (\Exception $e) {
        // Handle the exception
    }

    $darkSky = new PhpDarkSky('[API KEY]', '[LATITUDE]', '[LONGITUDE]');
    
    try {
        $foreacast = $darkSky->getCurrentForecast();
    } catch (\Exception $e) {
        // Handle the exception
    }

    $darkSky = new PhpDarkSky('[API KEY]', '[LATITUDE]', '[LONGITUDE]');
    
    try {
        $foreacast = $darkSky->getTimeMachine('[UNIX TIMESTAMP]');
    } catch (\Exception $e) {
        // Handle the exception
    }