/[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.3 by joko, Wed Dec 11 01:00:22 2002 UTC revision 1.5 by joko, Tue Feb 4 08:22:34 2003 UTC
# Line 3  Line 3 
3  //    $Id$  //    $Id$
4  //    -----------------------------------------------------------------------------  //    -----------------------------------------------------------------------------
5  //    $Log$  //    $Log$
6    //    Revision 1.5  2003/02/04 08:22:34  joko
7    //    + function is_hash
8    //    + function array_join_merge
9    //
10    //    Revision 1.4  2002/12/22 13:29:54  jonen
11    //    + added number format helper functions:
12    //      + number_format_locale()
13    //      + is_amount()
14    //
15  //    Revision 1.3  2002/12/11 01:00:22  joko  //    Revision 1.3  2002/12/11 01:00:22  joko
16  //    + renamed function 'sai' to 'array_init'  //    + renamed function 'sai' to 'array_init'
17  //  //
# Line 67  function array_init(&$var, $clear = 0) { Line 76  function array_init(&$var, $clear = 0) {
76    
77  // format functions  // format functions
78  function isvalidemailaddress($mail) {  function isvalidemailaddress($mail) {
79      // TODO: review for regex process load
80    //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));
81    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) ) {
82          return "format";          return "format";
# Line 152  function dprint($message) { Line 162  function dprint($message) {
162  }  }
163  */  */
164    
165    function number_format_storage($string) {
166        $locale_info = localeconv();
167        $string =  str_replace($locale_info["decimal_point"], ".",  $string);
168        return $string;
169    }
170    
171    function number_format_locale1($string) {
172        $locale_info = localeconv();
173        $string =  str_replace(".", $locale_info["decimal_point"],  $string);
174        return $string;
175    }
176    
177    
178    function number_format_locale ($num, $decimals = null) {
179       $locale = localeconv();
180       if(!isset($decimals)) $decimals = $locale['frac_digits'];
181       return number_format($num, $decimals, $locale['decimal_point'], $locale['thousands_sep']);
182    }
183    
184    
185    function is_amount($amount) {
186      //if( (number_format_locale((string)doubleval($amount)) === number_format_locale((string)$amount)) && number_format_locale((doubleval($amount)) >number_format_locale(0)) ) {
187      if( ((string)doubleval($amount) === (string)$amount) && (doubleval($amount) > 0) ) {
188        return 1;
189      }
190    }
191    
192    
193    // from: php.net - http://www.php.net/manual/en/function.array-merge-recursive.php
194    function is_hash( $var ) {
195     if( is_array( $var ) ) {
196       $keys = array_keys( $var );
197       $all_num = true;
198       for( $i=0; $i<count($keys); $i++ )
199         if( is_string($keys[$i] ) ) return true;
200     }
201     return false;
202    }
203    
204    // from: php.net - http://www.php.net/manual/en/function.array-merge-recursive.php
205    function array_join_merge( $arr1, $arr2 ) {
206     if( is_array( $arr1 ) and is_array( $arr2 ) ) {
207       // the same -> merge
208       $new_array = array();
209    
210       if( is_hash( $arr1 ) and is_hash( $arr2 ) ) {
211        // hashes -> merge based on keys
212         $keys = array_merge( array_keys( $arr1 ), array_keys( $arr2 ) );
213         foreach( $keys as $key ) {
214    $new_array[$key] = array_join_merge( $arr1[$key], $arr2[$key] );
215         }
216       } else {
217         // two real arrays -> merge
218         $new_array =
219    array_reverse(array_unique(array_reverse(array_merge($arr1,$arr2))));
220      }
221        
222       return $new_array;
223     } else {
224       // not the same ... take new one if defined, else the old one stays
225       return $arr2 ? $arr2 : $arr1;
226     }
227    }
228    
229  ?>  ?>

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.5

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