• 首页
  • css3教程
  • html5教程
  • jQuery手册
  • php7教程
  • MySQL手册
  • apache手册
  • 位置: php7教程

    php7国际化功能

    运行时配置

    这些函数的行为受php.ini中的设置影响。

    Intl 配置选项
    名字默认可修改范围更新日志
    intl.default_localePHP_INI_ALL
    intl.error_level0PHP_INI_ALL
    intl.use_exceptions0PHP_INI_ALLAvailable since PHP 5.5 and PECL 3.0.0a1

    这是配置指令的简短说明。


    intl.default_localestring

    The locale that will be used in intl functions when none is specified (either by omitting the corresponding argument or by passingNULL). These are ICU locales, not system locales. The built-in ICU locales and their data can be explored at » http://demo.icu-project.org/icu-bin/locexp.

    The default value is empty, which forces the usage of ICU's default locale. Once set, the ini setting cannot be reset to this default value. It is not recommended that this default be relied on, as its effective value depends on the server's environment.

    intl.error_levelinteger

    The level of the error messages generated when an error occurs in ICU functions. This is a PHP error level, such as E_WARNING. It can be set to0in order to inhibit the messages. This does not affect the return values indicating error or the values returned by intl_get_error_code() or by the class specific methods for retrieving error codes and messages. ChoosingE_ERRORwill terminate the script whenever an error condition is found on intl classes.

    The default value is0.

    intl.use_exceptionsinteger

    If set to true, an exception will be raised whenever an error occurs in an intl function. The exception will be of type IntlException. This is possibly in addition to the error message generated due to intl.error_level.

    The default value is FALSE.

    国际化功能基本用法

    每个模块提供两种api:过程api和对象api定向的。两者实际上是相同的,并在相应的文件。

    Note:

    All input strings must be in UTF-8 encoding. All output strings are also in UTF-8.

    Example #1 Example of using the procedural API

    <?php
    $coll  = collator_create('en_US');
    $result = collator_compare($coll, "string#1", "string#2");
    ?>
    

    Example #2 Example of using the object-oriented API

    <?php
    $coll = new Collator('en_US');
    $al   = $coll->getLocale(Locale::ACTUAL_LOCALE);
    echo "Actual locale: $al\n";
    $formatter = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
    echo $formatter->format(1234567);
    ?>
    
    Get the default currency for a country:
    <?php
    $formatter = new NumberFormatter('de_DE', NumberFormatter::CURRENCY);
    echo $formatter->getTextAttribute(NumberFormatter::CURRENCY_CODE);
    $formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY);
    echo $formatter->getTextAttribute(NumberFormatter::CURRENCY_CODE);
    $formatter = new NumberFormatter('ja_JP', NumberFormatter::CURRENCY);
    echo $formatter->getTextAttribute(NumberFormatter::CURRENCY_CODE);
    ?>