downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ltrim> <levenshtein
[edit] Last updated: Fri, 10 Feb 2012

view this page in

localeconv

(PHP 4 >= 4.0.5, PHP 5)

localeconv数値に関するフォーマット情報を得る

説明

array localeconv ( void )

ローカルな数値および通貨フォーマット情報を有する連想配列を返します。

返り値

localeconv() は、 setlocale() で設定された現在のロケールに基づきデータを返します。 返される連想配列は、次のフィールドを有します。

配列要素 説明
decimal_point 小数点文字
thousands_sep 千毎の区切り文字
grouping 数値集合を有する配列
int_curr_symbol 国際通貨記号 (すなわち、USD)
currency_symbol ローカルな通貨記号 (すなわち、$)
mon_decimal_point 通貨用の小数点文字
mon_thousands_sep 通貨用の千毎の区切り文字
mon_grouping 通貨集合を有する配列
positive_sign 正の値を表す記号
negative_sign 負の値を表す記号
int_frac_digits 国際分割桁
frac_digits ローカルな分割桁
p_cs_precedes currency_symbol が正の値を前に置く場合にTRUE、後に置く場合に FALSE
p_sep_by_space 正の値から currency_symbol を1文字の空白で区切る場合にTRUE、 そうでない場合にFALSE
n_cs_precedes currency_symbol が負の値を前に置く場合にTRUE、後に置く場合に FALSE
n_sep_by_space 負の値から currency_symbol を1文字の空白で区切る場合にTRUE、 そうでない場合にFALSE
p_sign_posn
  • 0 - 量および通貨記号を括る括弧
  • 1 - 量および通貨記号の前に置く符号文字列
  • 2 - 量および通貨記号の後に置く符号文字列
  • 3 - 通貨記号の直前に置く符号文字列
  • 4 - 通貨記号の直後に置く符号文字列
n_sign_posn
  • 0 - 量および通貨記号を括る括弧
  • 1 - 量および通貨記号の前に置く符号文字列
  • 2 - 量および通貨記号の後に置く符号文字列
  • 3 - 通貨記号の直前に置く符号文字列
  • 4 - 通貨記号の直後に置く符号文字列

n_sign_posnn_sign_posn は、フォーマッタオプションの文字列を含みます。それぞれの数字は 上に一覧されている条件の 1 つを表します。

groupingフィールドには、グループ化する方法を表す数字を定義する配 列が含まれます。例えば、nl_NL ロケール用の通貨 groupingフィールド (UTF-8 モードでのユーロ記号) には、 3、3を値とする要素数2の配列が含まれます。この配列のより高い添字に は、より左側のグループに関するものが含まれます。 ある配列要素が、CHAR_MAX に等しい場合、 さらにグループは行われません。配列要素が0に等しい場合、 前の要素が使用されています。

例1 localeconv() の例

<?php
if (false !== setlocale(LC_ALL'nl_NL.UTF-8@euro')) {
    
$locale_info localeconv();
    
print_r($locale_info);
}
?>

上の例の出力は以下となります。

Array
(
    [decimal_point] => .
    [thousands_sep] =>
    [int_curr_symbol] => EUR
    [currency_symbol] => €
    [mon_decimal_point] => ,
    [mon_thousands_sep] =>
    [positive_sign] =>
    [negative_sign] => -
    [int_frac_digits] => 2
    [frac_digits] => 2
    [p_cs_precedes] => 1
    [p_sep_by_space] => 1
    [n_cs_precedes] => 1
    [n_sep_by_space] => 1
    [p_sign_posn] => 1
    [n_sign_posn] => 2
    [grouping] => Array
        (
        )

    [mon_grouping] => Array
        (
            [0] => 3
            [1] => 3
        )

)

参考



add a note add a note User Contributed Notes localeconv
PixEye dot DELETE at bigfoot dot com 24-Nov-2007 01:15
A function to get the right money & number formats:
<?php
function displayLocales($number, $isMoney, $lg='en_US.utf8') {
   
$ret = setLocale(LC_ALL, $lg);
   
setLocale(LC_TIME, 'Europe/Paris');
    if (
$ret===FALSE) {
        echo
"Language '$lg' is not supported by this system.\n";
        return;
    }
   
$LocaleConfig = localeConv();
    forEach(
$LocaleConfig as $key => $val) $$key = $val;

   
// Sign specifications:
   
if ($number>0) {
       
$sign = $positive_sign;
       
$sign_posn = $p_sign_posn;
       
$sep_by_space = $p_sep_by_space;
       
$cs_precedes = $p_cs_precedes;
    } else {
       
$sign = $negative_sign;
       
$sign_posn = $n_sign_posn;
       
$sep_by_space = $n_sep_by_space;
       
$cs_precedes = $n_cs_precedes;
    }

   
// Number format:
   
$n = number_format(abs($number), $frac_digits,
       
$decimal_point, $thousands_sep);
   
$n = str_replace(' ', '&nbsp;', $n);
    switch(
$sign_posn) {
        case
0: $n = "($n)"; break;
        case
1: $n = "$sign$n"; break;
        case
2: $n = "$n$sign"; break;
        case
3: $n = "$sign$n"; break;
        case
4: $n = "$n$sign"; break;
        default:
$n = "$n [error sign_posn=$sign_posn&nbsp;!]";
    }

   
// Currency format:
   
$m = number_format(abs($number), $frac_digits,
       
$mon_decimal_point, $mon_thousands_sep);
    if (
$sep_by_space) $space = ' '; else $space = '';
    if (
$cs_precedes) $m = "$currency_symbol$space$m";
    else
$m = "$m$space$currency_symbol";
   
$m = str_replace(' ', '&nbsp;', $m);
    switch(
$sign_posn) {
        case
0: $m = "($m)"; break;
        case
1: $m = "$sign$m"; break;
        case
2: $m = "$m$sign"; break;
        case
3: $m = "$sign$m"; break;
        case
4: $m = "$m$sign"; break;
        default:
$m = "$m [error sign_posn=$sign_posn&nbsp;!]";
    }
    if (
$isMoney) return $m; else return $n;
}

$number = -12345.12345;
echo
'<div>'.displayLocales($number, FALSE)."</div>\n";
echo
'<div>'.displayLocales($number, TRUE)."</div>\n";
?>
verdy_p at wanadoo dot fr 22-Jul-2001 07:13
The C99 standard modified slightly the definition of the international currency symbol, which is now 4 characters long instead of 3 in previous definitions. The fourth character will most often be an ASCII space, but its effective value is the locale-specific spacing character used for numeric grouping (i.e. the one refered by [sep_by_space] and [grouping])...

 
show source | credits | stats | sitemap | contact | advertising | mirror sites