PHP code example of solaris / php-moon-phase

1. Go to this page and download the library: Download solaris/php-moon-phase 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/ */

    

solaris / php-moon-phase example snippets




use Solaris\MoonPhase;

$moonPhase = new MoonPhase();

$age = round($moonPhase->getAge(), 1);
$stage = $moonPhase->getPhase() < 0.5 ? 'waxing' : 'waning';
$distance = round($moonPhase->getDistance(), 2);
$next = gmdate('G:i:s, j M Y', (int) $moonPhase->getPhaseNextNewMoon());

echo 'The moon is currently ' . $age . ' days old, and is therefore ' . $stage . '. ';
echo 'It is ' . $distance . ' km from the centre of the Earth. ';
echo 'The next new moon is at ' . $next . '. ';