Skip to content

Instantly share code, notes, and snippets.

View mtttmpl's full-sized avatar

Matthew Temple mtttmpl

View GitHub Profile
@mtttmpl
mtttmpl / get_1900_date.php
Created January 8, 2014 12:20
1900 Date System converter to PHP takes $date as unix time and returns days since 1900.
<?php
function get_1900_date($date) {
$start = strtotime("1900-01-01");
$diff = $date - $start;
$days = $diff / 86400;
return round($days, 0);
}
?>
@mtttmpl
mtttmpl / br2nl.php
Last active December 13, 2015 16:58
Convert <br> tags to new lines
<?php
function br2nl($string) {
return preg_replace('=<br */?>=i', "\n", $string);
}
?>
@mtttmpl
mtttmpl / relative-time.php
Created September 29, 2012 16:51
Get Relative Time in PHP (e.g. '1 hour ago', 'yesterday', 'tomorrow', 'in 2 weeks')
<?php
function time2str($ts) {
if(!ctype_digit($ts)) {
$ts = strtotime($ts);
}
$diff = time() - $ts;
if($diff == 0) {
return 'now';
} elseif($diff > 0) {
$day_diff = floor($diff / 86400);