+ return preg_replace('|^0|', '', strftime('%m'));
+}
+
+# return today's date in yyyy-mm-dd format
+function today_ymd() {
+ return strftime('%Y-%m-%d');
+}
+
+function now_yyyymmdd() {
+ return strftime('%Y-%m-%d');
+}
+
+function now_yyyymmddhhmmss() {
+ return strftime('%Y-%m-%d %H:%M:%S');
+}
+
+
+function get_text_between($text, $start_text, $end_text) {
+ $start = strpos($text, $start_text);
+ if($start === false) {
+ return false;
+ }
+ $text = substr($text, $start + strlen($start_text));
+ $end = strpos($text, $end_text);
+ if($end === false) {
+ return false;
+ }
+ return substr($text, 0, $end);
+}
+
+# Make it easy to insert an array into the template data structure so that each
+# element of the array gets its own row.
+#
+# passed this: columnize(array('a', 'b', 'c'), 'k');
+# it returns: array(array('k' => 'a'),
+# array('k' => 'b'),
+# array('k' => 'c'));
+# passed this: columnate(array(), 'k');
+# it returns: false
+function columnize($arr, $key = 'data') {
+ if(!$arr) {
+ return false;
+ }
+ $ret = array();
+ foreach($arr as $val) {
+ $ret[] = array($key => $val);
+ }
+ return $ret;
+}
+
+# php4 is broken, in that you cannot set a default value for a parameter that
+# is passed by reference. So, this is set up to use the following screwy
+# syntax:
+#
+# function foo($bar = 0) {
+# if($bar !== 0) {
+# $bar = $bar->ref;
+# }
+# ...
+# }
+#
+# foo();
+# foo(ref($baz));
+
+class stupid_reference {
+ var $ref;
+ function stupid_reference(&$ref) {
+ $this->ref = &$ref;
+ }
+}
+function ref(&$foo) {
+ return new stupid_reference($foo);
+}
+
+function &last(&$array) {
+ if(count($array)) return $array[count($array) - 1];