3 |
// $Id$ |
// $Id$ |
4 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
5 |
// $Log$ |
// $Log$ |
6 |
|
// Revision 1.9 2004/09/07 18:52:01 jonen |
7 |
|
// added function 'format_amount' |
8 |
|
// |
9 |
|
// Revision 1.8 2003/03/03 21:21:43 joko |
10 |
|
// refactored most reusable code to org.netfrag.glib/php_extensions.php |
11 |
|
// |
12 |
|
// Revision 1.7 2003/03/01 05:05:55 joko |
13 |
|
// minor modification to 'Dumper' |
14 |
|
// |
15 |
|
// Revision 1.6 2003/02/09 17:49:53 joko |
16 |
|
// - removed old code |
17 |
|
// |
18 |
|
// Revision 1.5 2003/02/04 08:22:34 joko |
19 |
|
// + function is_hash |
20 |
|
// + function array_join_merge |
21 |
|
// |
22 |
|
// Revision 1.4 2002/12/22 13:29:54 jonen |
23 |
|
// + added number format helper functions: |
24 |
|
// + number_format_locale() |
25 |
|
// + is_amount() |
26 |
|
// |
27 |
|
// Revision 1.3 2002/12/11 01:00:22 joko |
28 |
|
// + renamed function 'sai' to 'array_init' |
29 |
|
// |
30 |
|
// Revision 1.2 2002/12/01 04:49:54 joko |
31 |
|
// + function Dumper (from function dumpVar) |
32 |
|
// |
33 |
// Revision 1.1 2002/11/12 05:42:31 joko |
// Revision 1.1 2002/11/12 05:42:31 joko |
34 |
// + initial checkin |
// + initial checkin |
35 |
// |
// |
77 |
return $date_res; |
return $date_res; |
78 |
} |
} |
79 |
|
|
|
// ------------------------------------------------- |
|
|
// sophisticated array init |
|
|
// initializes passed variable (taken by reference) with an empty array |
|
|
// does this only if it doesn't exist yet or initialization is explicitely requested ($clear = 1) |
|
|
function sai(&$var, $clear = 0) { |
|
|
if (!is_array($var) || $clear) { $var = array(); } |
|
|
} |
|
80 |
|
|
81 |
|
|
82 |
// format functions |
// format functions |
83 |
|
// refactor to org.netfrag.glib::php??? |
84 |
|
// refactor to Data::Validator??? |
85 |
function isvalidemailaddress($mail) { |
function isvalidemailaddress($mail) { |
86 |
|
// TODO: review for regex process load |
87 |
//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)); |
88 |
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) ) { |
89 |
return "format"; |
return "format"; |
90 |
} |
} |
91 |
elseif( gethostbyname($regs[2]) == $regs[2] ) { |
elseif( gethostbynamel($regs[2]) == $regs[2] ) { |
92 |
return "host"; |
return "host"; |
93 |
} |
} |
94 |
return "valid"; |
return "valid"; |
95 |
} |
} |
96 |
|
|
|
function dumpVar($var) { |
|
|
ob_start(); |
|
|
print_r($var); |
|
|
$var_dump = ob_get_contents(); |
|
|
ob_end_clean(); |
|
|
$var_dump = str_replace("\n", "<br>", $var_dump); |
|
|
$var_dump = str_replace(" ", " ", $var_dump); |
|
|
return $var_dump; |
|
|
} |
|
|
|
|
|
function session_register_safe($varname) { |
|
|
if (!session_is_registered($varname)) { |
|
|
session_register($varname); |
|
|
return 1; |
|
|
} |
|
|
} |
|
97 |
|
|
98 |
//------------ getMonths --------------------- |
//------------ getMonths --------------------- |
99 |
// TODO: localize! |
// TODO: localize! |
106 |
return $months; |
return $months; |
107 |
} |
} |
108 |
|
|
109 |
|
|
110 |
|
// refactor to Data::Lift??? |
111 |
function null2nbsp_string($arg) { |
function null2nbsp_string($arg) { |
112 |
if ($arg == '') { |
if ($arg == '') { |
113 |
$arg = ' '; |
$arg = ' '; |
115 |
return $arg; |
return $arg; |
116 |
} |
} |
117 |
|
|
118 |
|
// refactor to Data::Lift??? |
119 |
function null2nbsp_arraywalker(&$item, $key) { |
function null2nbsp_arraywalker(&$item, $key) { |
120 |
$item = null2nbsp_string($item); |
$item = null2nbsp_string($item); |
121 |
} |
} |
122 |
|
|
123 |
|
// refactor to Data::Lift??? |
124 |
function null2nbsp($arg) { |
function null2nbsp($arg) { |
125 |
if (is_array($arg)) { |
if (is_array($arg)) { |
126 |
array_walk($arg, 'null2nbsp_arraywalker'); |
array_walk($arg, 'null2nbsp_arraywalker'); |
145 |
return $birthday; |
return $birthday; |
146 |
} |
} |
147 |
|
|
148 |
/* |
function number_format_storage($string) { |
149 |
function dprint($message) { |
$locale_info = localeconv(); |
150 |
print '<span style="font-family:Verdana,Helvetica;font-size:7pt;">'; |
$string = str_replace($locale_info["decimal_point"], ".", $string); |
151 |
print $message; |
return $string; |
152 |
print '</span><br>'; |
} |
153 |
|
|
154 |
|
function number_format_locale1($string) { |
155 |
|
$locale_info = localeconv(); |
156 |
|
$string = str_replace(".", $locale_info["decimal_point"], $string); |
157 |
|
return $string; |
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
|
function number_format_locale ($num, $decimals = null) { |
162 |
|
$locale = localeconv(); |
163 |
|
//if(!isset($decimals)) $decimals = $locale['frac_digits']; |
164 |
|
if(!isset($decimals)) $decimals = 2; |
165 |
|
return number_format($num, $decimals, $locale['decimal_point'], $locale['thousands_sep']); |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
// refactor to org.netfrag.glib::php??? |
170 |
|
// rename to 'check_amount'? |
171 |
|
// move to Data::Validator??? |
172 |
|
function is_amount($amount) { |
173 |
|
//if( (number_format_locale((string)doubleval($amount)) === number_format_locale((string)$amount)) && number_format_locale((doubleval($amount)) >number_format_locale(0)) ) { |
174 |
|
if( ((string)doubleval($amount) === (string)$amount) && (doubleval($amount) > 0) ) { |
175 |
|
return 1; |
176 |
|
} |
177 |
} |
} |
178 |
*/ |
|
179 |
|
function format_amount(&$amount) { |
180 |
|
$amount = str_replace(array(".", ","), array("", "."), $amount); |
181 |
|
//print "streplace amount: '$amount'<br>"; |
182 |
|
//return $amount; |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
?> |
?> |