Author Topic: Looking for a competent php expert  (Read 3533 times)

TechnoMonkey

  • Strong Breeze
  • ***
  • Posts: 127
    • EW9323
    • KTXARANS6
    • TechnoMonkeys Weather
  • Station Details: La Crosse WS-2315 / High Sierra Server / Mac Mini 2.3 GHz Intel Core i5/ 8GB Ram / OS 120GB SSD / Home Folder 500GB FireWire / DATA 8TB RAID 5 / 1TB TIME CAPSULE
Looking for a competent php expert
« on: February 06, 2016, 03:02:30 PM »
I have been unable to understand how to use the return value from the moonrise/moonset script I found.  The source did not have anything but the class, no example for access.

Code: [Select]
class Moon {

/**
* Calculates the moon rise/set for a given location and day of year
*/
public static function calculateMoonTimes($month, $day, $year, $lat, $lon) {


/* for brevity, calculations were done here and left out as I do not think it pertinent to my question. */

// Convert to unix timestamps and return as an object
$retVal = new stdClass();
$utrise = self::convertTime($utrise);
$utset = self::convertTime($utset);
$retVal->moonrise = $rise ? mktime($utrise['hrs'], $utrise['min'], 0, $month, $day, $year) : mktime(0, 0, 0, $month, $day + 1, $year);
$retVal->moonset = $set ? mktime($utset['hrs'], $utset['min'], 0, $month, $day, $year) : mktime(0, 0, 0, $month, $day + 1, $year);
            return $retVal;

I am able to get the info through brute force, but it seems that I should be able to use '$retVal' for a cleaner code.  I just do not know how.  I have tried googling php sites and all the testing I do either returns a blank page or server error.

My brute force respnse;

Code: [Select]
   //should be cleaner, but works for now
    $v = var_export(Moon::calculateMoonTimes($month, $day, $year, $lat, $lon), true);

    $moonrise = substr($v,46,10)."<br>";
    $moonset = substr($v,74,10)."<br>";
   
    $rise = date("H:i", $moonrise);
    $set = date("H:i", $moonset);

awilltx

  • Guest
Re: Lokking for a competent php expert
« Reply #1 on: February 06, 2016, 03:25:38 PM »
Hello technomonkey,


You might try posting your question/problem at [size=78%]http://www.wxforum.net[/size]. Of course, you will need an active profile to post, but no big deal.


There is an entire forum at [/size][size=78%]http://www.wxforum.net/index.php?board=87.0[/size]  for php and scripting and many developers who are active there.


Good luck,


Alan

wvdkuil

  • Strong Breeze
  • ***
  • Posts: 151
    • DW8113 (D8113)
    • IVLAAMSG47
    • Weatherstation Wilsele/Leuven/Belgium
  • Station Details: VantagePro2+ UV,Solar - Macbook/Mini
Re: Lokking for a competent php expert
« Reply #2 on: February 06, 2016, 05:32:32 PM »
The script returns an object (kind of array) so it needs the -> addressing
You can always use a var_dump to see the different "fields" returned in the object
Using this code with my current  time/lat/lon:
Code: [Select]
$var = Moon::calculateMoonTimes($month, $day, $year, $lat, $lon);

$rise = date("H:i", $var -> moonrise);
$set  = date("H:i", $var -> moonset);

echo '<br />$rise = '.$rise;
echo '<br />$set = '.$set;
Returns this output:
Code: [Select]
$rise = 05:18
$set = 14:34

Hope this explains it enough/
Wim
Support of Leuven-Template&Scripts: https://support.leuven-template.eu/
Support and demo for the PWS_Dashboard (also for WeatherCat)  https://pwsdashboard.com/ 
My PWS at home https://weer.sluispark.be/
And at my daughters house https://www.weerstation-herent.be/

TechnoMonkey

  • Strong Breeze
  • ***
  • Posts: 127
    • EW9323
    • KTXARANS6
    • TechnoMonkeys Weather
  • Station Details: La Crosse WS-2315 / High Sierra Server / Mac Mini 2.3 GHz Intel Core i5/ 8GB Ram / OS 120GB SSD / Home Folder 500GB FireWire / DATA 8TB RAID 5 / 1TB TIME CAPSULE
Re: Looking for a competent php expert
« Reply #3 on: February 06, 2016, 05:49:39 PM »
Perfect. Thanks!

"$var -> moonrise" <- that was the part I was getting wrong in my attempts.

I am still a newbie dealing with objects and classes.  Initially I started with php just to eliminate redundant information like menus etc. on my pages and progressed into calculations.  Switch/case was great for readability of long if/else statements.  Php is great.  Still learning.

Thanks again.

(typos do not help either, just noticed I spelled "looking" wrong.)