X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=encode.php;h=e79dae2b6d82946ccb0b508b00bc103f3baa86b7;hb=51cf6721f37220e1277c71545b87dcc01fbf7e81;hp=8a41eebda0562371003d1114d93e19864a6142be;hpb=f929f48ccd3dcd231921972a792cfc44be742268;p=wfpl.git diff --git a/encode.php b/encode.php index 8a41eeb..e79dae2 100644 --- a/encode.php +++ b/encode.php @@ -28,10 +28,18 @@ function enc_cap($str) { return $str; } +# quote for placing between single quotes in php +function enc_phpsq($str) { + $str = str_replace("\\", "\\\\", $str); + $str = str_replace("'", "\\'", $str); + return $str; +} + function enc_jsdq($str) { $str = enc_sql($str); $str = str_replace("\n", "\\n", $str); - return str_replace("\r", "\\r", $str); + $str = str_replace("\r", "\\r", $str); + return $str; } # encode for putting within double-quotes in SQL @@ -174,11 +182,16 @@ function enc_mdy($str) { return enc_mmddyyyy($str); } -function enc_mmddyyyyhhmm($seconds) { - return date('m/d/Y g:ia', (int)$seconds); +# pass unix timestamp or "2012-12-20 22:23:34" +function enc_mmddyyyyhhmm($str) { + if(is_numeric($str)) { + return date('m/d/Y g:ia', (int)$str); + } else { + return enc_mmddyyyy(substr($str, 0, 10)) . substr($str, 10, 6); + } } -# takes decimal +# takes decimal number of hours # returns hh:mm function enc_hhmm($str) { if(strlen($str) == 0) { @@ -190,7 +203,7 @@ function enc_hhmm($str) { return $str; } -# takes decimal +# takes decimal number of hours # returns hh:mm followed by "am" or "pm" with no space function enc_12hr($str) { if(strlen($str) == 0) { @@ -457,3 +470,12 @@ function enc_linkify($str) { } return $ret; } + +# turns a filename into the unix timestamp of that files modification date +function enc_mtime($dummy, $filename) { + $stat = stat($filename); + if ($stat === false) { + return ''; + } + return '' . $stat['mtime']; +}