3 |
// $Id$ |
// $Id$ |
4 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
5 |
// $Log$ |
// $Log$ |
6 |
|
// Revision 1.7 2003/03/01 05:05:55 joko |
7 |
|
// minor modification to 'Dumper' |
8 |
|
// |
9 |
|
// Revision 1.6 2003/02/09 17:49:53 joko |
10 |
|
// - removed old code |
11 |
|
// |
12 |
|
// Revision 1.5 2003/02/04 08:22:34 joko |
13 |
|
// + function is_hash |
14 |
|
// + function array_join_merge |
15 |
|
// |
16 |
|
// Revision 1.4 2002/12/22 13:29:54 jonen |
17 |
|
// + added number format helper functions: |
18 |
|
// + number_format_locale() |
19 |
|
// + is_amount() |
20 |
|
// |
21 |
|
// Revision 1.3 2002/12/11 01:00:22 joko |
22 |
|
// + renamed function 'sai' to 'array_init' |
23 |
|
// |
24 |
// Revision 1.2 2002/12/01 04:49:54 joko |
// Revision 1.2 2002/12/01 04:49:54 joko |
25 |
// + function Dumper (from function dumpVar) |
// + function Dumper (from function dumpVar) |
26 |
// |
// |
72 |
} |
} |
73 |
|
|
74 |
// ------------------------------------------------- |
// ------------------------------------------------- |
75 |
// sophisticated array init |
// array initializer |
76 |
// initializes passed variable (taken by reference) with an empty array |
// initializes passed variable (taken by reference) with an empty array |
77 |
// 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) |
78 |
function sai(&$var, $clear = 0) { |
function array_init(&$var, $clear = 0) { |
79 |
if (!is_array($var) || $clear) { $var = array(); } |
if (!is_array($var) || $clear) { $var = array(); } |
80 |
} |
} |
81 |
|
|
82 |
|
|
83 |
// format functions |
// format functions |
84 |
function isvalidemailaddress($mail) { |
function isvalidemailaddress($mail) { |
85 |
|
// TODO: review for regex process load |
86 |
//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)); |
87 |
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) ) { |
88 |
return "format"; |
return "format"; |
93 |
return "valid"; |
return "valid"; |
94 |
} |
} |
95 |
|
|
96 |
function dumpVar($var) { |
function Dumper() { |
|
return Dumper($var); |
|
|
} |
|
|
|
|
|
function Dumper($var) { |
|
97 |
ob_start(); |
ob_start(); |
98 |
print_r($var); |
$arg_list = func_get_args(); |
99 |
|
$count = 1; |
100 |
|
foreach ($arg_list as $arg) { |
101 |
|
//print "<hr/>"; |
102 |
|
print_r($arg); |
103 |
|
$count++; |
104 |
|
} |
105 |
$var_dump = ob_get_contents(); |
$var_dump = ob_get_contents(); |
106 |
ob_end_clean(); |
ob_end_clean(); |
107 |
$var_dump = str_replace("\n", "<br>", $var_dump); |
$var_dump = str_replace("\n", "<br>", $var_dump); |
162 |
return $birthday; |
return $birthday; |
163 |
} |
} |
164 |
|
|
165 |
/* |
function number_format_storage($string) { |
166 |
function dprint($message) { |
$locale_info = localeconv(); |
167 |
print '<span style="font-family:Verdana,Helvetica;font-size:7pt;">'; |
$string = str_replace($locale_info["decimal_point"], ".", $string); |
168 |
print $message; |
return $string; |
|
print '</span><br>'; |
|
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 |
?> |
?> |