/[cvs]/nfo/php/libs/org.netfrag.flib/utils/helper.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.flib/utils/helper.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by joko, Tue Nov 12 05:42:31 2002 UTC revision 1.6 by joko, Sun Feb 9 17:49:53 2003 UTC
# Line 3  Line 3 
3  //    $Id$  //    $Id$
4  //    -----------------------------------------------------------------------------  //    -----------------------------------------------------------------------------
5  //    $Log$  //    $Log$
6    //    Revision 1.6  2003/02/09 17:49:53  joko
7    //    - removed old code
8    //
9    //    Revision 1.5  2003/02/04 08:22:34  joko
10    //    + function is_hash
11    //    + function array_join_merge
12    //
13    //    Revision 1.4  2002/12/22 13:29:54  jonen
14    //    + added number format helper functions:
15    //      + number_format_locale()
16    //      + is_amount()
17    //
18    //    Revision 1.3  2002/12/11 01:00:22  joko
19    //    + renamed function 'sai' to 'array_init'
20    //
21    //    Revision 1.2  2002/12/01 04:49:54  joko
22    //    + function Dumper (from function dumpVar)
23    //
24  //    Revision 1.1  2002/11/12 05:42:31  joko  //    Revision 1.1  2002/11/12 05:42:31  joko
25  //    + initial checkin  //    + initial checkin
26  //  //
# Line 51  function get_date_forStorage($arg_date) Line 69  function get_date_forStorage($arg_date)
69  }  }
70    
71  // -------------------------------------------------  // -------------------------------------------------
72  // sophisticated array init  // array initializer
73  // initializes passed variable (taken by reference) with an empty array  // initializes passed variable (taken by reference) with an empty array
74  // does this only if it doesn't exist yet or initialization is explicitely requested ($clear = 1)  // does this only if it doesn't exist yet or initialization is explicitely requested ($clear = 1)
75  function sai(&$var, $clear = 0) {  function array_init(&$var, $clear = 0) {
76    if (!is_array($var) || $clear) { $var = array(); }    if (!is_array($var) || $clear) { $var = array(); }
77  }  }
78        
79    
80  // format functions  // format functions
81  function isvalidemailaddress($mail) {  function isvalidemailaddress($mail) {
82      // TODO: review for regex process load
83    //return ((($string = trim($string)) != '') && (($atpos = strpos($string, '@' , 1)) > 1) && (($rdotpos = strrpos($string, '.')) > ($atpos + 2)) && (strlen($string) > $rdotpos + 2));    //return ((($string = trim($string)) != '') && (($atpos = strpos($string, '@' , 1)) > 1) && (($rdotpos = strrpos($string, '.')) > ($atpos + 2)) && (strlen($string) > $rdotpos + 2));
84    if( !eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*"."@([a-z0-9]+([\.-][a-z0-9]+))*$",$mail, $regs) ) {    if( !eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*"."@([a-z0-9]+([\.-][a-z0-9]+))*$",$mail, $regs) ) {
85          return "format";          return "format";
# Line 71  function isvalidemailaddress($mail) { Line 90  function isvalidemailaddress($mail) {
90    return "valid";    return "valid";
91  }  }
92    
93  function dumpVar($var) {  function Dumper() {
94    ob_start();    ob_start();
95    print_r($var);    $arg_list = func_get_args();
96      $count = 1;
97      foreach ($arg_list as $arg) {
98        print "<hr/>";
99        print_r($arg);
100        $count++;
101      }
102    $var_dump = ob_get_contents();    $var_dump = ob_get_contents();
103    ob_end_clean();    ob_end_clean();
104    $var_dump = str_replace("\n", "<br>", $var_dump);    $var_dump = str_replace("\n", "<br>", $var_dump);
# Line 134  function getEncodedBirthdate($birthdate) Line 159  function getEncodedBirthdate($birthdate)
159    return $birthday;    return $birthday;
160  }  }
161    
162  /*  function number_format_storage($string) {
163  function dprint($message) {      $locale_info = localeconv();
164    print '<span style="font-family:Verdana,Helvetica;font-size:7pt;">';      $string =  str_replace($locale_info["decimal_point"], ".",  $string);
165    print $message;      return $string;
   print '</span><br>';  
166  }  }
167  */  
168    function number_format_locale1($string) {
169        $locale_info = localeconv();
170        $string =  str_replace(".", $locale_info["decimal_point"],  $string);
171        return $string;
172    }
173    
174    
175    function number_format_locale ($num, $decimals = null) {
176       $locale = localeconv();
177       if(!isset($decimals)) $decimals = $locale['frac_digits'];
178       return number_format($num, $decimals, $locale['decimal_point'], $locale['thousands_sep']);
179    }
180    
181    
182    function is_amount($amount) {
183      //if( (number_format_locale((string)doubleval($amount)) === number_format_locale((string)$amount)) && number_format_locale((doubleval($amount)) >number_format_locale(0)) ) {
184      if( ((string)doubleval($amount) === (string)$amount) && (doubleval($amount) > 0) ) {
185        return 1;
186      }
187    }
188    
189    
190    // from: php.net - http://www.php.net/manual/en/function.array-merge-recursive.php
191    function is_hash( $var ) {
192     if( is_array( $var ) ) {
193       $keys = array_keys( $var );
194       $all_num = true;
195       for( $i=0; $i<count($keys); $i++ )
196         if( is_string($keys[$i] ) ) return true;
197     }
198     return false;
199    }
200    
201    // from: php.net - http://www.php.net/manual/en/function.array-merge-recursive.php
202    function array_join_merge( $arr1, $arr2 ) {
203     if( is_array( $arr1 ) and is_array( $arr2 ) ) {
204       // the same -> merge
205       $new_array = array();
206    
207       if( is_hash( $arr1 ) and is_hash( $arr2 ) ) {
208        // hashes -> merge based on keys
209         $keys = array_merge( array_keys( $arr1 ), array_keys( $arr2 ) );
210         foreach( $keys as $key ) {
211    $new_array[$key] = array_join_merge( $arr1[$key], $arr2[$key] );
212         }
213       } else {
214         // two real arrays -> merge
215         $new_array =
216    array_reverse(array_unique(array_reverse(array_merge($arr1,$arr2))));
217      }
218        
219       return $new_array;
220     } else {
221       // not the same ... take new one if defined, else the old one stays
222       return $arr2 ? $arr2 : $arr1;
223     }
224    }
225    
226  ?>  ?>

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.6

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed