Date: 07/11/00
- Next message: kk: "[phplib-dev] cvs commit"
- Previous message: ssilk: "[phplib-dev] cvs commit"
- Next in thread: kk: "[phplib-dev] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: ssilk
Date: Wed Jul 12 01:29:26 2000
Modified files:
php-lib/php/strings2.inc
Log message:
New (useful) functions. But I think about splitting it up into several
files or renaming string2.inc into usefull.inc. (?)
- iso8859p1strtolower($str), iso8859p1strtoupper($str):
Returns all possible alpha-chars of ISO-LATIN-1 charset (ISO 8859 page 1)
in lowercase/UPPERCASE. this is not dependend on chosen language!
- timestart($start=false):
Start stopwatch with stopwatch('start');
Get interval-time with: $seconds=stopwatch();
- timewatch($format,$time,$string=''):
outputs a time (seconds) as a duration
like "1d 02:23:32.432"
format is currently only "%x" or "%s"
%x formats like above, %s returns only seconds
if $time is negative the time from the last call is subtracted
(interval time)
$string is an optional sprintf() format-option
This is not the very fastest function - I have found similar functions
which work faster, but I think timstart() and timewatch() are a very
flexible solution.
- function mkdir_path ($filename,$rights)
can take an absolute or relative file- or dirname
and creates a path with $rights if dir is not existing.
If function returns true you can be sure that the dir is
existing.
Index: php-lib/php/strings2.inc
diff -u php-lib/php/strings2.inc:1.3 php-lib/php/strings2.inc:1.4
--- php-lib/php/strings2.inc:1.3 Mon Mar 20 02:35:54 2000
+++ php-lib/php/strings2.inc Wed Jul 12 01:28:55 2000
@@ -8,7 +8,7 @@
## C a little bit better it will be placed directly in PHP3.
## But I can't... :-}
##
-## $Id: strings2.inc,v 1.3 2000/03/20 01:35:54 ssilk Exp $
+## $Id: strings2.inc,v 1.4 2000/07/11 23:28:55 ssilk Exp $
##
@@ -105,4 +105,101 @@
function p_nonbsp ($val) {
print o_nonbsp($val);
}
+
+
+##
+## Returns all possible alpha-chars of ISO-LATIN-1 charset
+## (ISO 8859 page 1) in lowercase/UPPERCASE
+## this is not dependend on chosen language!
+##
+function iso8859p1strtolower($str) {
+ return(strstr($str,
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ',
+ 'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ'));
+}
+
+function iso8859p1strtoupper($str) {
+ return(strstr($str,
+ 'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ',
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ'));
+}
+
+##
+## This is not a string-function, but very usefull.
+## Start stopwatch with:
+## stopwatch('start');
+## Get interval-time with:
+## $seconds=stopwatch();
+## output seconds with duration_time() (see there)
+##
+function timestart($start=false) {
+STATIC $starttime;
+ list($a,$b)=split(' ',microtime());
+ $mt=$a+$b;
+ if (!empty($start)) {
+ $starttime=$mt;
+ return($starttime);
+ } else {
+ return($mt-$starttime);
+ }
+}
+
+##
+## outputs a time (seconds) as a duration
+## like "1d 02:23:32.432"
+## format is currently only "%x" or "%s"
+## %x formats like above, %s returns only seconds
+## if $time is negative the time from the last call is subtracted
+## (interval time)
+## $string is an optional sprintf() format-option
+##
+function timewatch($format,$time,$string='') {
+STATIC $last_t=0;
+ if (empty($format))
+ die('duration_time(): $format is empty.');
+
+ if ($time<0) {
+ $t=-$time-$last_t;
+ $last_t=$t;
+ } else {
+ $last_t=$t=$time;
+ }
+ if ($format=='%s') {
+ $r=sprintf('%12.4f',$t);
+ } elseif ($format=='%x') {
+ $days=(int)((int)$t / 86400);
+ $restdays=(int)((int)$t % 86400);
+ $secs=(double)((int)$t % 60)+((double)$t-(double)(int)$t);
+ $r=o_iftrue($days,"%sd ").gmdate("H:i:",$restdays).o_iftrue($secs,"%02.4f");
+ } else {
+ die("duration_time(): Unknown format '$format'");
+ }
+ if (!empty($string)) {
+ return(sprintf($string,$r));
+ } else {
+ return($r);
+ }
+}
+
+#
+# can take an absolute or relative file- or dirname
+# and creates a path with $rights if dir is not existing.
+# If function returns true you can be sure that the dir is
+# existing.
+#
+function mkdir_path ($filename,$rights) {
+ $dir=dirname($filename);
+ if ($dir==$filename) return(true);
+ if (!is_dir($dir)) {
+ if (mkdir_path($dir,$rights)) {
+ if (!mkdir($dir,$rights))
+ return(false);
+ } else {
+ return(true);
+ }
+ }
+ return(true);
+}
+
+
?>
---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-dev-unsubscribe <email protected>
For additional commands, e-mail: phplib-dev-help <email protected>
- Next message: kk: "[phplib-dev] cvs commit"
- Previous message: ssilk: "[phplib-dev] cvs commit"
- Next in thread: kk: "[phplib-dev] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

