note 14215 deleted from function.localeconv by irchtml

From: Date: Fri, 27 Feb 2004 11:12:57 +0000
Subject: note 14215 deleted from function.localeconv by irchtml
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-65876@lists.php.net to get a copy of this message
Note Submitter: verdy_p@wanadoo.fr ---- [p_sep_by_space] and [n_sep_by_space]values are not more boolean values, as specified by the C99 standard set by the Open Group. Their effective value are: 0: no space between currency,value and sign 1: a space separates the currency symbol and the value; if a sign is present between the currency symbol and the value, then the space is inserted just beside the value, grouping the currency symbol and the sign symbol 2: a space separates the currency symbol and the value; if a sign is present the currency symbol and the value, the space is inserted just between the currency symbol and the group formed by the value and its sign The following array displays the appropriate format, where '$' should be replaced by the currency symbol, ' ' should be replaced by the locale space separator, '+' is replaced by the localized sign symbol, and '1' is replaced by the formated value: $mon_format = array( // 1, $ succedes , $ precedes 1 // ( precedes, $1, ) succedes 0=> array(0=> array(FALSE=> '(1$)' , TRUE=> '($1)' ), // no space 1=> array(FALSE=> '(1 $)', TRUE=> '($ 1)'), // space sep +$ 1 2=> array(FALSE=> '(1 $)', TRUE=> '($ 1)')), // space sep + $1 // + precedes, $1 1=> array(0=> array(FALSE=> '+1$' , TRUE=> '+$1' ), // no space 1=> array(FALSE=> '+1 $' , TRUE=> '+$ 1' ), // space sep $ 1 2=> array(FALSE=> '+1 $' , TRUE=> '+ $1' )), // space sep $ + // $1, + succedes 2=> array(0=> array(FALSE=> '1$+' , TRUE=> '$1+' ), // no space 1=> array(FALSE=> '1 $+' , TRUE=> '$ 1+' ), // space sep $ 1 2=> array(FALSE=> '1$ +' , TRUE=> '$1 +' )), // space sep $ + // + precedes, $ 3=> array(0=> array(FALSE=> '1+$' , TRUE=> '+$1' ), // no space 1=> array(FALSE=> '1 +$' , TRUE=> '+$ 1' ), // space sep $ 1 1=> array(FALSE=> '1+ $' , TRUE=> '+ $1' )), // space sep $ + // $, + succedes 4=> array(0=> array(FALSE=> '1$+' , TRUE=> '$+1' ), // no space 1=> array(FALSE=> '1 $+' , TRUE=> '$+ 1' ), // space sep $ 1 2=> array(FALSE=> '1$ +' , TRUE=> '$ +1' ))); // space sep $ + Note that locale index values used above only work if the index is not MAX_CHAR (127), which means that the corresponding locale value is not specified. The default "C" locale only defines '.' as the standard decimal separator, and does not define any grouping, and not any thousands separator or currency symbols (they are empty strings). The fractional digits, cs_precedes, sep_by_space, and sign_pos values are all returned as MAX_CHAR (127), which means that they are application defined. For compatibility, one should handle 127 values as if they were all 1, i.e. currency sign DOES precede the value, a space is present between the currency and the value, and a leading sign is present. And with a value of 127 for sign_posn, one should consider that the negative sign is '-', or that the positive sign will be empty. A value of MAX_CHAR (127) is also returned for the currency sign position when the currency symbol is empty. Note that the C99 standard defines new locale settings not shown here. One can add them by using the following PHP function: function getlocaleconv($locale_name) { global $localeconv; if (!isset($locales)) $localeconv = array(); if (isset($localeconv[$locale_name])) return $localeconv[$locale_name]; $old_locale = setlocale(LC_ALL, 0); setlocale(LC_ALL, $locale_name); $locale = localeconv(); setlocale(LC_ALL, $old_locale); if (!isset($locale[decimal_point])) $locale[decimal_point] = '.'; if (!isset($locale[positive_sign])) $locale[positive_sign] = '+'; if (!isset($locale[negative_sign])) $locale[negative_sign] = '-'; if (!isset($locale[thousands_sep])) { if ($locale[decimal_point] == ',') $locale[thousands_sep] = ' '; else $locale[thousands_sep] = ','; } if (!isset($locale[grouping]) || empty($locale[grouping])) $locale[grouping] = array(3); if (!isset($locale[mon_decimal_point])) $locale[mon_decimal_point] = $locale[decimal_point]; if (!isset($locale[mon_negative_sign])) $locale[mon_negative_sign] = $locale[negative_sign]; if (!isset($locale[mon_positive_sign])) $locale[mon_positive_sign] = ''; if (!isset($locale[mon_thousands_sep])) { $locale[mon_thousands_sep] = $locale[thousands_sep]; if ($locale[mon_thousands_sep] == $locale[mon_decimal_point]) { if ($locale[mon_decimal_point] == ',') $locale[mon_thousands_sep] = ' '; else $locale[mon_thousands_sep] = ','; } } if (!isset($locale[currency_symbol])) $locale[currency_symbol] = '$'; if (!isset($locale[frac_digits])) $locale[frac_digits] = 2; if (!isset($locale[p_cs_precedes])) $locale[p_cs_precedes] = true; if (!isset($locale[n_cs_precedes])) $locale[n_cs_precedes] = $locale[p_cs_precedes]; if (!isset($locale[p_sep_by_space])) $locale[p_sep_by_space] = 0; if (!isset($locale[n_sep_by_space])) $locale[n_sep_by_space] = $locale[p_sep_by_space]; if (!isset($locale[p_sign_posn])) $locale[p_sign_posn] = 0; if (!isset($locale[n_sign_posn])) $locale[n_sign_posn] = $locale[p_sign_posn]; if (!isset($locale[int_curr_symbol])) { // Ugly defaults, try to get the international country code... if (strlen($locale_name) >= 5 && substr($locale_name.substring,2,1) == '_') $locale[int_curr_symbol] = strtoupper(substr($locale_name.substring, 2, 2)); else if (strlen($locale_name) >= 2) $locale[int_curr_symbol] = strtoupper(substr($locale_name.substring, 0, 2)); else $locale[int_curr_symbol] = 'XX'; } if (strlen($locale[currency_symbol]) == 2) { // Ugly defaults: try to get the international currency initial if (substr($locale[currency_symbol], 1, 1) == '$') $locale[int_curr_symbol] .= 'D'; else if (substr($locale[currency_symbol], 1, 1) == '£') $locale[int_curr_symbol] .= 'P'; else if (substr($locale[currency_symbol], 1, 1) == 'ƒ') $locale[int_curr_symbol] .= 'G'; else if (substr($locale[currency_symbol], 1, 1) == '¥') $locale[int_curr_symbol] .= 'Y'; else if (substr($locale[currency_symbol], 1, 1) == 'DM') $locale[int_curr_symbol] .= 'M'; else if (isletter(substr($locale[currency_symbol], 1, 1))) $locale[int_curr_symbol] .= strtoupper(substr($locale[currency_symbol], 1, 1)); else // Unknown currency code for this country code $locale[int_curr_symbol] .= 'X'; } // Default grouping space separator if (strlen($locale[int_curr_symbol]) == 3) $locale[int_curr_symbol] .= ' '; if (!isset($locale[int_frac_digits])) $locale[int_frac_digits] = $locale[frac_digits]; if (!isset($locale[int_p_cs_precedes])) $locale[int_p_cs_precedes] = $locale[p_cs_precedes]; if (!isset($locale[int_n_cs_precedes])) $locale[int_n_cs_precedes] = $locale[n_cs_precedes]; if (!isset($locale[int_p_sep_by_space])) $locale[int_p_sep_by_space] = $locale[p_sep_by_space]; if (!isset($locale[int_n_sep_by_space])) $locale[int_n_sep_by_space] = $locale[n_sep_by_space]; if (!isset($locale[int_p_sign_posn])) $locale[int_p_sign_posn] = $locale[p_sign_posn]; if (!isset($locale[int_p_sign_posn])) $locale[int_n_sign_posn] = $locale[n_sign_posn]; return $localeconv[$locale_name] = $locale; }

« previous php.notes (#65876) next »