summaryrefslogtreecommitdiff
path: root/bin/utils.php
diff options
context:
space:
mode:
authorTheTroll <trolldev@gmail.com>2010-03-16 15:16:59 +0100
committerTheTroll <trolldev@gmail.com>2010-03-16 15:16:59 +0100
commite89fdef6064741bf6d26c11b782c7fecf994caf3 (patch)
tree2d3214ed31948f344ca069fb214c53ce298e3778 /bin/utils.php
parent5400c2d66985a85591b2b78085615cd2826911a4 (diff)
downloadistreamdev-e89fdef6064741bf6d26c11b782c7fecf994caf3.tar.gz
istreamdev-e89fdef6064741bf6d26c11b782c7fecf994caf3.tar.bz2
Function implementation WIP
Diffstat (limited to 'bin/utils.php')
-rwxr-xr-xbin/utils.php95
1 files changed, 95 insertions, 0 deletions
diff --git a/bin/utils.php b/bin/utils.php
new file mode 100755
index 0000000..e748c64
--- /dev/null
+++ b/bin/utils.php
@@ -0,0 +1,95 @@
+<?php
+function is_utf8($str)
+{
+ $c=0; $b=0;
+ $bits=0;
+ $len=strlen($str);
+ for($i=0; $i<$len; $i++)
+ {
+ $c=ord($str[$i]);
+ if($c > 128)
+ {
+ if(($c >= 254)) return false;
+ elseif($c >= 252) $bits=6;
+ elseif($c >= 248) $bits=5;
+ elseif($c >= 240) $bits=4;
+ elseif($c >= 224) $bits=3;
+ elseif($c >= 192) $bits=2;
+ else return false;
+ if(($i+$bits) > $len) return false;
+ while($bits > 1)
+ {
+ $i++;
+ $b=ord($str[$i]);
+ if($b < 128 || $b > 191) return false;
+ $bits--;
+ }
+ }
+ }
+ return true;
+}
+
+function php2js ($var)
+{
+ if (is_array($var))
+ {
+ $array = array();
+
+ foreach ($var as $a_var)
+ $array[] = php2js($a_var);
+
+ return str_replace("\"", "'", join(",", $array));
+
+
+ }
+
+ elseif (is_bool($var))
+ return ($var ? "true" : "false");
+
+ elseif (is_int($var) || is_integer($var) || is_double($var) || is_float($var))
+ return $var;
+
+ elseif (is_string($var))
+ return "\"" .$var . "\"";
+
+ else
+ return false;
+}
+
+function sec2hms ($sec, $padHours = false)
+{
+
+ // holds formatted string
+ $hms = "";
+
+ // there are 3600 seconds in an hour, so if we
+ // divide total seconds by 3600 and throw away
+ // the remainder, we've got the number of hours
+ $hours = intval(intval($sec) / 3600);
+
+ // add to $hms, with a leading 0 if asked for
+ $hms .= ($padHours)
+ ? str_pad($hours, 2, "0", STR_PAD_LEFT). ':'
+ : $hours. ':';
+
+ // dividing the total seconds by 60 will give us
+ // the number of minutes, but we're interested in
+ // minutes past the hour: to get that, we need to
+ // divide by 60 again and keep the remainder
+ $minutes = intval(($sec / 60) % 60);
+
+ // then add to $hms (with a leading 0 if needed)
+ $hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':';
+
+ // seconds are simple - just divide the total
+ // seconds by 60 and keep the remainder
+ $seconds = intval($sec % 60);
+
+ // add to $hms, again with a leading 0 if needed
+ $hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);
+
+ // done!
+ return $hms;
+
+}
+?>