= 11) && (($number % 100) <= 13)) { return $number.'th'; } else { return $number.$suffix[$number % 10]; } } // generate uuid function gen_uuid() { return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', // 32 bits for "time_low" mt_rand(0, 0xffff), mt_rand(0, 0xffff), // 16 bits for "time_mid" mt_rand(0, 0xffff), // 16 bits for "time_hi_and_version", // four most significant bits holds version number 4 mt_rand(0, 0x0fff) | 0x4000, // 16 bits, 8 bits for "clk_seq_hi_res", // 8 bits for "clk_seq_low", // two most significant bits holds zero and one for variant DCE1.1 mt_rand(0, 0x3fff) | 0x8000, // 48 bits for "node" mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); } // slope intercept form: y = mx + b function sif($x = '', $x1 = '', $y1 = '', $x2 = '', $y2 = '') { $y = 0; if(!empty($x, $x1, $y1, $x2, $y2)) { $m = ($y2 - $y1) / ($x2 - $x1); $b = $y1 - $m * $x1; $y = $m * $x + $b; } return $y; } // convert float to fraction as array function float2fraction($float = '') { $out[0] = 0; $out[1] = 0; $out[2] = 0; if(!empty($float) && is_float($float)) { $float = trim($float, '0'); $parts = explode('.', $float); $numerator = $parts[1]; $denominator = pow(10, strlen($parts[1])); $gcf = gmp_strval(gmp_gcd($numerator, $denominator)); $out[0] = $parts[0]; $out[1] = $numerator / $gcf; $out[2] = $denominator / $gcf; } return $out; } // output fraction array as html function fraction($fraction = '') { $out = 0; if(!empty($fraction) && is_array($fraction) && count($fraction) == 3) { if($fraction[0] > 0) { $out = $fraction[0]; } if($fraction[1] > 0 && $fraction[2] > 0) { $out .= ''.$fraction[1].''.$fraction[2].''; } } return $out; } // convert fraction array to float function fraction2float($fraction = '') { $out = 0; if(!empty($fraction) && is_array($fraction) && count($fraction) == 3 && is_numeric($fraction[0]) && is_numeric($fraction[1]) && $fraction[1] > 0 && is_numeric($fraction[2]) && $fraction[2] > 0) { $out = $fraction[0] + ($fraction[1] / $fraction[2]); } return $out; } $fraction = float2fraction(3.141); print(fraction($fraction).' = '.fraction2float($fraction)); /******************************* time ****************************************/ // unixtime // note: always store an initial start date forever $now = microtime(true); // as float $now = time(); // list of timezones print_r(timezone_identifiers_list()); print_r(DateTimeZone::listIdentifiers(DateTimeZone::AMERICA)); // list of timezone abbreviations print_r(timezone_abbreviations_list()); // set default timezone // note: ********** always set default timezone ********** // note: ********** always set default timezone ********** // note: ********** always set default timezone ********** date_default_timezone_set('America/Toronto'); // get server default timezone $tz = date_default_timezone_get(); // date validation if(checkdate($date['month'], $date['day'], $date['year'])) { // valid date } // unixtime information as array print_r(getdate(1746734049)); // format unixtime // list of valid date formats: https://www.php.net/manual/en/datetime.format.php print(date('Y-m-d H:i:s T', $now)); // convert string to unixtime // list of valid time string formats: https://www.php.net/manual/en/datetime.formats.php $ts = strtotime('2025-03-01 15:25:35'); $ts = strtotime('2025-03-01 15:25:35 UTC'); $ts = strtotime('2025-03-01 15:25:35 EST'); // adding/subtracting to unixtime $ts = strtotime('+1 year', $now); $ts = strtotime('12 month', $now); $ts = strtotime('52 week', $now); $ts = strtotime('365 day', $now); $ts = strtotime('1 year 1 month 3 day 4 hour -2 minute -30 second', $now); $ts = strtotime('next sunday +1 week', $now); $ts = strtotime('first day of this month', $now); $ts = strtotime('previous sunday', $now); // tricks $ts = strtotime('last day of 2025-03'); $ts = strtotime('2025-04-00'); // last day of previous month $ts = strtotime('last day of 2025-04 -1 month'); $ts = strtotime('first monday of 2025-03'); $ts = strtotime('last monday of 2025-03'); $ts = strtotime('tomorrow +6 year'); // html calendar function minical($time = '') { if(empty($time)) { $time = time(); } $today = date('j'); $tomonth = date('Y-m'); $month = date('Y-m', $time); $startdow = date('w', strtotime('first day of this month', $time)); if($startdow > 0) { $startstart = date('j', strtotime('last day of last month', $time)) - $startdow + 1; } else { $startstart = 0; } $enddow = 6 - date('w', strtotime('last day of this month', $time)); $lastday = date('t', $time); $day = date('j', $time); $title = date('F Y', $time); $calendar = ''; for($i = 0; $i < ($startdow + $lastday + $enddow); $i++) { if($i > 0 && ($i % 7) == 0) { // new row $calendar .= ''; } if($startdow > $i) { // begin blanks $calendar .= ''; } else if($i < ($startdow + $lastday)) { // date if(($i - $startdow + 1) == $today && $month == $tomonth) { // today $css = ' style="font-weight: bold;background-color: #ffd100;"'; } else { $css = ''; } $calendar .= ''.($i - $startdow + 1).''; } else { // end blanks $calendar .= ''; } } $calendar .= '
'.$title.'
SuMoTuWeThFrSa
'.($startstart + $i).''.($i - $startdow - $lastday + 1).'
'; return $calendar; } print(minical(time())); ?>