Internationalization Functions

目录

简介

Provides string comparison capability with support for appropriate locale-sensitive sort orderings.

类摘要

Collator

class Collator {

/* 方法 */

public __construct ( string $locale )

public bool asort ( array &$arr [, int $sort_flag ] )

public int compare ( string $str1 , string $str2 )

public static Collator create ( string $locale )

public int getAttribute ( int $attr )

public int getErrorCode ( void )

public string getErrorMessage ( void )

public string getLocale ( int $type )

public string getSortKey ( string $str )

public int getStrength ( void )

public bool setAttribute ( int $attr , int $val )

public bool setStrength ( int $strength )

public bool sortWithSortKeys ( array &$arr )

public bool sort ( array &$arr [, int $sort_flag ] )

}

预定义常量

Collator::FRENCH_COLLATION (integer)
Sort strings with different accents from the back of the string. This attribute is automatically set to On for the French locales and a few others. Users normally would not need to explicitly set this attribute. There is a string comparison performance cost when it is set On, but sort key length is unaffected. Possible values are:

  • Collator::ON
  • Collator::OFF(default)
  • Collator::DEFAULT_VALUE

示例 #1 FRENCH_COLLATION rules

  • F=OFF cote < coté < côte < côté
  • F=ON cote < côte < coté < côté

Collator::ALTERNATE_HANDLING (integer)
The Alternate attribute is used to control the handling of the so called variable characters in the UCA: whitespace, punctuation and symbols. If Alternate is set to NonIgnorable (N), then differences among these characters are of the same importance as differences among letters. If Alternate is set to Shifted (S), then these characters are of only minor importance. The Shifted value is often used in combination with Strength set to Quaternary. In such a case, whitespace, punctuation, and symbols are considered when comparing strings, but only if all other aspects of the strings (base letters, accents, and case) are identical. If Alternate is not set to Shifted, then there is no difference between a Strength of 3 and a Strength of 4. For more information and examples, see Variable_Weighting in the » UCA. The reason the Alternate values are not simply On and Off is that additional Alternate values may be added in the future. The UCA option Blanked is expressed with Strength set to 3, and Alternate set to Shifted. The default for most locales is NonIgnorable. If Shifted is selected, it may be slower if there are many strings that are the same except for punctuation; sort key length will not be affected unless the strength level is also increased.

Possible values are:

  • Collator::NON_IGNORABLE(default)
  • Collator::SHIFTED
  • Collator::DEFAULT_VALUE

示例 #2 ALTERNATE_HANDLING rules

  • S=3, A=N di Silva < Di Silva < diSilva < U.S.A. < USA
  • S=3, A=S di Silva = diSilva < Di Silva < U.S.A. = USA
  • S=4, A=S di Silva < diSilva < Di Silva < U.S.A. < USA

Collator::CASE_FIRST (integer)
The Case_First attribute is used to control whether uppercase letters come before lowercase letters or vice versa, in the absence of other differences in the strings. The possible values are Uppercase_First (U) and Lowercase_First (L), plus the standard Default and Off. There is almost no difference between the Off and Lowercase_First options in terms of results, so typically users will not use Lowercase_First: only Off or Uppercase_First. (People interested in the detailed differences between X and L should consult the Collation Customization). Specifying either L or U won't affect string comparison performance, but will affect the sort key length.

Possible values are:

  • Collator::OFF(default)
  • Collator::LOWER_FIRST
  • Collator::UPPER_FIRST
  • Collator:DEFAULT

示例 #3 CASE_FIRST rules

  • C=X or C=L "china" < "China" < "denmark" < "Denmark"
  • C=U "China" < "china" < "Denmark" < "denmark"

Collator::CASE_LEVEL (integer)
The Case_Level attribute is used when ignoring accents but not case. In such a situation, set Strength to be Primary, and Case_Level to be On. In most locales, this setting is Off by default. There is a small string comparison performance and sort key impact if this attribute is set to be On.

Possible values are:

  • Collator::OFF(default)
  • Collator::ON
  • Collator::DEFAULT_VALUE

示例 #4 CASE_LEVEL rules

  • S=1, E=X role = Role = rôle
  • S=1, E=O role = rôle < Role

Collator::NORMALIZATION_MODE (integer)
The Normalization setting determines whether text is thoroughly normalized or not in comparison. Even if the setting is off (which is the default for many locales), text as represented in common usage will compare correctly (for details, see UTN #5). Only if the accent marks are in noncanonical order will there be a problem. If the setting is On, then the best results are guaranteed for all possible text input. There is a medium string comparison performance cost if this attribute is On, depending on the frequency of sequences that require normalization. There is no significant effect on sort key length. If the input text is known to be in NFD or NFKD normalization forms, there is no need to enable this Normalization option.

Possible values are:

  • Collator::OFF(default)
  • Collator::ON
  • Collator::DEFAULT_VALUE

Collator::STRENGTH (integer)
The ICU Collation Service supports many levels of comparison (named "Levels", but also known as "Strengths"). Having these categories enables ICU to sort strings precisely according to local conventions. However, by allowing the levels to be selectively employed, searching for a string in text can be performed with various matching conditions. For more detailed information, see collator_set_strength chapter.

Possible values are:

  • Collator::PRIMARY
  • Collator::SECONDARY
  • Collator::TERTIARY(default)
  • Collator::QUATERNARY
  • Collator::IDENTICAL
  • Collator::DEFAULT_VALUE

Collator::HIRAGANA_QUATERNARY_MODE (integer)
Compatibility with JIS x 4061 requires the introduction of an additional level to distinguish Hiragana and Katakana characters. If compatibility with that standard is required, then this attribute should be set On, and the strength set to Quaternary. This will affect sort key length and string comparison string comparison performance.

Possible values are:

  • Collator::OFF(default)
  • Collator::ON
  • Collator::DEFAULT_VALUE

Collator::NUMERIC_COLLATION (integer)
When turned on, this attribute generates a collation key for the numeric value of substrings of digits. This is a way to get '100' to sort AFTER '2'.

Possible values are:

  • Collator::OFF(default)
  • Collator::ON
  • Collator::DEFAULT_VALUE

Collator::DEFAULT_VALUE (integer)

Collator::PRIMARY (integer)

Collator::SECONDARY (integer)

Collator::TERTIARY (integer)

Collator::DEFAULT_STRENGTH (integer)

Collator::QUATERNARY (integer)

Collator::IDENTICAL (integer)

Collator::OFF (integer)

Collator::ON (integer)

Collator::SHIFTED (integer)

Collator::NON_IGNORABLE (integer)

Collator::LOWER_FIRST (integer)

Collator::UPPER_FIRST (integer)

Collator::asort

collator_asort

Sort array maintaining index association

说明

面向对象风格

public bool Collator::asort ( array &$arr [, int $sort_flag ] )

过程化风格

bool collator_asort ( Collator $coll , array &$arr [, int $sort_flag ] )

This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. This is used mainly when sorting associative arrays where the actual element order is significant. Array elements will have sort order according to current locale rules.

Equivalent to standard PHP asort.

参数

coll
Collator object.

arr
Array of strings to sort.

sort_flag
Optional sorting type, one of the following:

  • Collator::SORT_REGULAR - compare items normally (don't change types)

  • Collator::SORT_NUMERIC - compare items numerically

  • Collator::SORT_STRING - compare items as strings

Default $sort_flag value is Collator::SORT_REGULAR. It is also used if an invalid $sort_flag value has been specified.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 collator_asortexample

<?php
$coll = collator_create( 'en_US' );
$arr = array(
     'a' => '100',
     'b' => '50',
     'c' => '7'
);
collator_asort( $coll, $arr, Collator::SORT_NUMERIC );
var_export( $arr );

collator_asort( $coll, $arr, Collator::SORT_STRING );
var_export( $arr );
?>

以上例程会输出:

array (
  'c' => '7',
  'b' => '50',
  'a' => '100',
)array (
  'a' => '100',
  'b' => '50',
  'c' => '7',
)

参见

Collator::compare

collator_compare

Compare two Unicode strings

说明

面向对象风格

public int Collator::compare ( string $str1 , string $str2 )

过程化风格

int collator_compare ( Collator $coll , string $str1 , string $str2 )

Compare two Unicode strings according to collation rules.

参数

coll
Collator object.

str1
The first string to compare.

str2
The second string to compare.

返回值

Return comparison result:

  • 1 if str1 is greater than str2 ;

  • 0 if str1 is equal to str2;

  • -1 if str1 is less than str2 .

On error boolean FALSE is returned.

Warning

此函数可能返回布尔值 FALSE,但也可能返回等同于 FALSE 的非布尔值。请阅读 布尔类型章节以获取更多信息。应使用 === 运算符来测试此函数的返回值。

范例

示例 #1 collator_compareexample

<?php
$s1 = 'Hello';
$s2 = 'hello';

$coll = collator_create( 'en_US' );
$res  = collator_compare( $coll, $s1, $s2 );

if ($res === false) {
    echo collator_get_error_message( $coll );
} else if( $res > 0 ) {
    echo "s1 is greater than s2\n";
} else if( $res < 0 ) {
    echo "s1 is less than s2\n";
} else {
    echo "s1 is equal to s2\n";
}
?>

以上例程会输出:

s1 is greater than s2

参见

  • collator_sort

Collator::__construct

Create a collator

说明

public Collator::__construct ( string $locale )

Creates a new instance of Collator.

参数

locale
The locale whose collation rules should be used. Special values for locales can be passed in - if null is passed for the locale, the default locale's collation rules will be used. If "root" is passed, UCA rules will be used.

The Locale attribute is typically the most important attribute for correct sorting and matching, according to the user expectations in different countries and regions. The default » UCA ordering will only sort a few languages such as Dutch and Portuguese correctly ("correctly" meaning according to the normal expectations for users of the languages). Otherwise, you need to supply the locale to UCA in order to properly collate text for a given language. Thus a locale needs to be supplied so as to choose a collator that is correctly tailored for that locale. The choice of a locale will automatically preset the values for all of the attributes to something that is reasonable for that locale. Thus most of the time the other attributes do not need to be explicitly set. In some cases, the choice of locale will make a difference in string comparison performance and/or sort key length.

返回值

Returns Collator instance.

错误/异常

Returns an "empty" object on error. You can use intl_get_error_code and/or intl_get_error_message to know what happened.

范例

示例 #1 Collator::__construct example

<?php
$coll = new Collator( 'en_CA' );
?>

参见

  • Collator::create
  • collator_create

Collator::create

collator_create

Create a collator

说明

面向对象风格

public static Collator Collator::create ( string $locale )

过程化风格

Collator collator_create ( string $locale )

The strings will be compared using the options already specified.

参数

locale
The locale containing the required collation rules. Special values for locales can be passed in - if null is passed for the locale, the default locale collation rules will be used. If empty string ("") or "root" are passed, » UCA rules will be used.

返回值

Return new instance of Collator object, or NULL on error.

范例

示例 #1 collator_create example

<?php
$coll = collator_create( 'en_US' );

if( !isset( $coll ) ) {
    printf( "Collator creation failed: %s\n", intl_get_error_message() );
    exit( 1 );
}
?>

参见

  • Collator::__construct

Collator::getAttribute

collator_get_attribute

Get collation attribute value

说明

面向对象风格

public int Collator::getAttribute ( int $attr )

过程化风格

int collator_get_attribute ( Collator $coll , int $attr )

Get a value of an integer collator attribute.

参数

coll
Collator object.

attr
Attribute to get value for.

返回值

Attribute value, or boolean FALSE on error.

范例

示例 #1 collator_get_attribute example

<?php
$coll = collator_create( 'en_CA' );
$val = collator_get_attribute( $coll, Collator::NUMERIC_COLLATION );
if( $val === false )
{
    // Handle error.
}
?>

参见

Collator::getErrorCode

collator_get_error_code

Get collator's last error code

说明

面向对象风格

public int Collator::getErrorCode ( void )

过程化风格

int collator_get_error_code ( Collator $coll )

参数

coll
Collator object.

返回值

Error code returned by the last Collator API function call.

范例

示例 #1 collator_get_error_code example

<?php
$coll = collator_create( 'en_US' );
if( collator_get_attribute( $coll, Collator::FRENCH_COLLATION ) === false )
        handle_error( collator_get_error_code() );
?>

参见

  • collator_get_error_message

Collator::getErrorMessage

collator_get_error_message

Get text for collator's last error code

说明

面向对象风格

public string Collator::getErrorMessage ( void )

过程化风格

string collator_get_error_message ( Collator $coll )

Retrieves the message for the last error.

参数

coll
Collator object.

返回值

Description of an error occurred in the last Collator API function call.

范例

示例 #1 collator_get_error_message example

<?php
$coll = collator_create( 'lt' );
if( collator_compare( $coll, 'y', 'k' ) === false ) {
    echo collator_get_error_message( $coll );
}
?>

参见

  • collator_get_error_code

Collator::getLocale

collator_get_locale

Get the locale name of the collator

说明

面向对象风格

public string Collator::getLocale ( int $type )

过程化风格

string collator_get_locale ( Collator $coll , int $type )

Get collector locale name.

参数

coll
Collator object.

type
You can choose between valid and actual locale ( Locale::VALID_LOCALE and Locale::ACTUAL_LOCALE, respectively).

返回值

Real locale name from which the collation data comes. If the collator was instantiated from rules or an error occurred, returns boolean FALSE.

范例

示例 #1 collator_get_locale example

<?php
$coll    = collator_create( 'en_US_California' );
$res_val = collator_get_locale( $coll, Locale::VALID_LOCALE );
$res_act = collator_get_locale( $coll, Locale::ACTUAL_LOCALE );
printf( "Valid locale name: %s\nActual locale name: %s\n",
         $res_val, $res_act );
?>

以上例程会输出:

Requested locale name: en_US_California
Valid locale name: en_US
Actual locale name: en

参见

  • collator_create

Collator::getSortKey

collator_get_sort_key

Get sorting key for a string

说明

面向对象风格

public string Collator::getSortKey ( string $str )

过程化风格

string collator_get_sort_key ( Collator $coll , string $str )

Return collation key for a string. Collation keys can be compared directly instead of strings, though are implementation specific and may change between ICU library versions. Sort keys are generally only useful in databases or other circumstances where function calls are extremely expensive.

参数

coll
Collator object.

str
The string to produce the key from.

返回值

Returns the collation key for the string, 或者在失败时返回 FALSE.

Warning

此函数可能返回布尔值 FALSE,但也可能返回等同于 FALSE 的非布尔值。请阅读 布尔类型章节以获取更多信息。应使用 === 运算符来测试此函数的返回值。

更新日志

版本说明
5.3.15, 5.4.5Sort keys do no longer contain any NUL bytes.

范例

示例 #1 collator_get_sort_keyexample

<?php
$s1 = 'Hello';

$coll = collator_create('en_US');
$res  = collator_get_sort_key($coll, $s1);

echo bin2hex($res);
?>

以上例程的输出类似于:

3832404046010901dc08

参见

  • collator_sort
  • collator_sort_with_sort_keys

Collator::getStrength

collator_get_strength

Get current collation strength

说明

面向对象风格

public int Collator::getStrength ( void )

过程化风格

int collator_get_strength ( Collator $coll )

参数

coll
Collator object.

返回值

Returns current collation strength, or boolean FALSE on error.

范例

示例 #1 collator_get_strength example

<?php
$coll     = collator_create( 'en_US' );
$strength = collator_get_strength( $coll );
?>

参见

Collator::setAttribute

collator_set_attribute

Set collation attribute

说明

面向对象风格

public bool Collator::setAttribute ( int $attr , int $val )

过程化风格

bool collator_set_attribute ( Collator $coll , int $attr , int $val )

参数

coll
Collator object.

attr
Attribute.

val
Attribute value.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 collator_set_attribute example

<?php
$coll = collator_create( 'en_CA' );
$val  = collator_get_attribute( $coll, Collator::NUMERIC_COLLATION );
if ($val === false) {
    // Handle error.
} elseif ($val === Collator::ON) {
    // Do something useful.
}
?>

参见

Collator::setStrength

collator_set_strength

Set collation strength

说明

面向对象风格

public bool Collator::setStrength ( int $strength )

过程化风格

bool collator_set_strength ( Collator $coll , int $strength )

The » ICU Collation Service supports many levels of comparison (named "Levels", but also known as "Strengths"). Having these categories enables ICU to sort strings precisely according to local conventions. However, by allowing the levels to be selectively employed, searching for a string in text can be performed with various matching conditions.

  1. Primary Level: Typically, this is used to denote differences between base characters (for example, "a" < "b"). It is the strongest difference. For example, dictionaries are divided into different sections by base character. This is also called the level1 strength.

  2. Secondary Level: Accents in the characters are considered secondary differences (for example, "as" < "às" < "at"). Other differences between letters can also be considered secondary differences, depending on the language. A secondary difference is ignored when there is a primary difference anywhere in the strings. This is also called the level2 strength.

    Note:

    Note: In some languages (such as Danish), certain accented letters are considered to be separate base characters. In most languages, however, an accented letter only has a secondary difference from the unaccented version of that letter.

  3. Tertiary Level: Upper and lower case differences in characters are distinguished at the tertiary level (for example, "ao" < "Ao" < "aò"). In addition, a variant of a letter differs from the base form on the tertiary level (such as "A" and " "). Another example is the difference between large and small Kana. A tertiary difference is ignored when there is a primary or secondary difference anywhere in the strings. This is also called the level3 strength.

  4. Quaternary Level: When punctuation is ignored (see Ignoring Punctuations ) at level 13, an additional level can be used to distinguish words with and without punctuation (for example, "ab" < "a-b" < "aB"). This difference is ignored when there is a primary, secondary or tertiary difference. This is also known as the level4 strength. The quaternary level should only be used if ignoring punctuation is required or when processing Japanese text (see Hiragana processing).

  5. Identical Level: When all other levels are equal, the identical level is used as a tiebreaker. The Unicode code point values of the NFD form of each string are compared at this level, just in case there is no difference at levels 14. For example, Hebrew cantillation marks are only distinguished at this level. This level should be used sparingly, as only code point values differences between two strings is an extremely rare occurrence. Using this level substantially decreases the performance for both incremental comparison and sort key generation (as well as increasing the sort key length). It is also known as level 5 strength.

For example, people may choose to ignore accents or ignore accents and case when searching for text. Almost all characters are distinguished by the first three levels, and in most locales the default value is thus Tertiary. However, if Alternate is set to be Shifted, then the Quaternary strength can be used to break ties among whitespace, punctuation, and symbols that would otherwise be ignored. If very fine distinctions among characters are required, then the Identical strength can be used (for example, Identical Strength distinguishes between the Mathematical Bold Small A and the Mathematical Italic Small A.). However, using levels higher than Tertiary the Identical strength result in significantly longer sort keys, and slower string comparison performance for equal strings.

参数

coll
Collator object.

strength
Strength to set.

Possible values are:

  • Collator::PRIMARY

  • Collator::SECONDARY

  • Collator::TERTIARY

  • Collator::QUATERNARY

  • Collator::IDENTICAL

  • Collator::DEFAULT_STRENGTH

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 collator_set_strength example

<?php
$arr  = array( 'aò', 'Ao', 'ao' );
$coll = collator_create( 'en_US' );

// Sort array using default strength.
collator_sort( $coll, $arr ); 
var_export( $arr );

// Sort array using primary strength.
collator_set_strength( $coll, Collator::PRIMARY );
collator_sort( $coll, $arr );
var_export( $arr );
?>

以上例程会输出:

array (
  0 => 'ao',
  1 => 'Ao',
  2 => 'aò',
)
array (
  0 => 'aò',
  1 => 'Ao',
  2 => 'ao',
)

参见

Collator::sortWithSortKeys

collator_sort_with_sort_keys

Sort array using specified collator and sort keys

说明

面向对象风格

public bool Collator::sortWithSortKeys ( array &$arr )

过程化风格

bool collator_sort_with_sort_keys ( Collator $coll , array &$arr )

Similar to collator_sort but uses ICU sorting keys produced by ucol_getSortKey() to gain more speed on large arrays.

参数

coll
Collator object.

arr
Array of strings to sort

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 collator_sort_with_sort_keys example

<?php
$arr  = array( 'Köpfe', 'Kypper', 'Kopfe' );
$coll = collator_create( 'sv' );

collator_sort_with_sort_keys( $coll, $arr );
var_export( $arr );
?>

以上例程会输出:

array (
  0 => 'Kopfe',
  1 => 'Kypper',
  2 => 'Köpfe',
)

参见

Collator::sort

collator_sort

Sort array using specified collator

说明

面向对象风格

public bool Collator::sort ( array &$arr [, int $sort_flag ] )

过程化风格

bool collator_sort ( Collator $coll , array &$arr [, int $sort_flag ] )

This function sorts an array according to current locale rules.

Equivalent to standard PHP sort .

参数

coll
Collator object.

arr
Array of strings to sort.

sort_flag
Optional sorting type, one of the following:

  • Collator::SORT_REGULAR - compare items normally (don't change types)

  • Collator::SORT_NUMERIC - compare items numerically

  • Collator::SORT_STRING - compare items as strings

Default sorting type is Collator::SORT_REGULAR. It is also used if an invalid sort_flag value has been specified.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 collator_sort example

<?php
$coll = collator_create( 'en_US' );
$arr  = array( 'at', 'às', 'as' );

var_export( $arr );
collator_sort( $coll, $arr );
var_export( $arr );
?>

以上例程会输出:

array (
  0 => 'at',
  1 => 'às',
  2 => 'as',
)array (
  0 => 'as',
  1 => 'às',
  2 => 'at',
)

参见

简介

Programs store and operate on numbers using a locale-independent binary representation. When displaying or printing a number it is converted to a locale-specific string. For example, the number 12345.67 is "12,345.67" in the US, "12 345,67" in France and "12.345,67" in Germany.

By invoking the methods provided by the NumberFormatter class, you can format numbers, currencies, and percentages according to the specified or default locale. NumberFormatter is locale-sensitive so you need to create a new NumberFormatter for each locale. NumberFormatter methods format primitive-type numbers, such as double and output the number as a locale-specific string.

For currencies you can use currency format type to create a formatter that returns a string with the formatted number and the appropriate currency sign. Of course, the NumberFormatter class is unaware of exchange rates so, the number output is the same regardless of the specified currency. This means that the same number has different monetary values depending on the currency locale. If the number is 9988776.65 the results will be:

  • 9 988 776,65 € in France
  • 9.988.776,65 € in Germany
  • $9,988,776.65 in the United States

In order to format percentages, create a locale-specific formatter with percentage format type. With this formatter, a decimal fraction such as 0.75 is displayed as 75%.

For more complex formatting, like spelled-out numbers, the rule-based number formatters are used.

类摘要

NumberFormatter

class NumberFormatter {

/* 方法 */

public __construct ( string $locale , int $style [, string $pattern ] )

public static NumberFormatter create ( string $locale , int $style [, string $pattern ] )

public string formatCurrency ( float $value , string $currency )

public string format ( number $value [, int $type ] )

public int getAttribute ( int $attr )

public int getErrorCode ( void )

public string getErrorMessage ( void )

public string getLocale ([ int $type ] )

public string getPattern ( void )

public string getSymbol ( int $attr )

public string getTextAttribute ( int $attr )

public float parseCurrency ( string $value , string &$currency [, int &$position ] )

public mixed parse ( string $value [, int $type [, int &$position ]] )

public bool setAttribute ( int $attr , int $value )

public bool setPattern ( string $pattern )

public bool setSymbol ( int $attr , string $value )

public bool setTextAttribute ( int $attr , string $value )

}

预定义常量

These styles are used by the numfmt_create to define the type of the formatter.

NumberFormatter::PATTERN_DECIMAL (integer)
Decimal format defined by pattern

NumberFormatter::DECIMAL (integer)
Decimal format

NumberFormatter::CURRENCY (integer)
Currency format

NumberFormatter::PERCENT (integer)
Percent format

NumberFormatter::SCIENTIFIC (integer)
Scientific format

NumberFormatter::SPELLOUT (integer)
Spellout rule-based format

NumberFormatter::ORDINAL (integer)
Ordinal rule-based format

NumberFormatter::DURATION (integer)
Duration rule-based format

NumberFormatter::PATTERN_RULEBASED (integer)
Rule-based format defined by pattern

NumberFormatter::CURRENCY_ACCOUNTING (integer)
Currency format for accounting, e.g., ($3.00) for negative currency amount instead of -$3.00. Available as of PHP 7.4.1 and ICU 53.

NumberFormatter::DEFAULT_STYLE (integer)
Default format for the locale

NumberFormatter::IGNORE (integer)
Alias for PATTERN_DECIMAL

These constants define how the numbers are parsed or formatted. They should be used as arguments to numfmt_format and numfmt_parse.

NumberFormatter::TYPE_DEFAULT (integer)
Derive the type from variable type

NumberFormatter::TYPE_INT32 (integer)
Format/parse as 32-bit integer

NumberFormatter::TYPE_INT64 (integer)
Format/parse as 64-bit integer

NumberFormatter::TYPE_DOUBLE (integer)
Format/parse as floating point value

NumberFormatter::TYPE_CURRENCY (integer)
Format/parse as currency value

Number format attribute used by numfmt_get_attribute and numfmt_set_attribute.

NumberFormatter::PARSE_INT_ONLY (integer)
Parse integers only.

NumberFormatter::GROUPING_USED (integer)
Use grouping separator.

NumberFormatter::DECIMAL_ALWAYS_SHOWN (integer)
Always show decimal point.

NumberFormatter::MAX_INTEGER_DIGITS (integer)
Maximum integer digits.

NumberFormatter::MIN_INTEGER_DIGITS (integer)
Minimum integer digits.

NumberFormatter::INTEGER_DIGITS (integer)
Integer digits.

NumberFormatter::MAX_FRACTION_DIGITS (integer)
Maximum fraction digits.

NumberFormatter::MIN_FRACTION_DIGITS (integer)
Minimum fraction digits.

NumberFormatter::FRACTION_DIGITS (integer)
Fraction digits.

NumberFormatter::MULTIPLIER (integer)
Multiplier.

NumberFormatter::GROUPING_SIZE (integer)
Grouping size.

NumberFormatter::ROUNDING_MODE (integer)
Rounding Mode.

NumberFormatter::ROUNDING_INCREMENT (integer)
Rounding increment.

NumberFormatter::FORMAT_WIDTH (integer)
The width to which the output of format() is padded.

NumberFormatter::PADDING_POSITION (integer)
The position at which padding will take place. See pad position constants for possible argument values.

NumberFormatter::SECONDARY_GROUPING_SIZE (integer)
Secondary grouping size.

NumberFormatter::SIGNIFICANT_DIGITS_USED (integer)
Use significant digits.

NumberFormatter::MIN_SIGNIFICANT_DIGITS (integer)
Minimum significant digits.

NumberFormatter::MAX_SIGNIFICANT_DIGITS (integer)
Maximum significant digits.

NumberFormatter::LENIENT_PARSE (integer)
Lenient parse mode used by rule-based formats.

Number format text attribute used by numfmt_get_text_attribute and numfmt_set_text_attribute.

NumberFormatter::POSITIVE_PREFIX (integer)
Positive prefix.

NumberFormatter::POSITIVE_SUFFIX (integer)
Positive suffix.

NumberFormatter::NEGATIVE_PREFIX (integer)
Negative prefix.

NumberFormatter::NEGATIVE_SUFFIX (integer)
Negative suffix.

NumberFormatter::PADDING_CHARACTER (integer)
The character used to pad to the format width.

NumberFormatter::CURRENCY_CODE (integer)
The ISO currency code.

NumberFormatter::DEFAULT_RULESET (integer)
The default rule set. This is only available with rule-based formatters.

NumberFormatter::PUBLIC_RULESETS (integer)
The public rule sets. This is only available with rule-based formatters. This is a read-only attribute. The public rulesets are returned as a single string, with each ruleset name delimited by ';' (semicolon).

Number format symbols used by numfmt_get_symbol and numfmt_set_symbol.

NumberFormatter::DECIMAL_SEPARATOR_SYMBOL (integer)
The decimal separator.

NumberFormatter::GROUPING_SEPARATOR_SYMBOL (integer)
The grouping separator.

NumberFormatter::PATTERN_SEPARATOR_SYMBOL (integer)
The pattern separator.

NumberFormatter::PERCENT_SYMBOL (integer)
The percent sign.

NumberFormatter::ZERO_DIGIT_SYMBOL (integer)
Zero.

NumberFormatter::DIGIT_SYMBOL (integer)
Character representing a digit in the pattern.

NumberFormatter::MINUS_SIGN_SYMBOL (integer)
The minus sign.

NumberFormatter::PLUS_SIGN_SYMBOL (integer)
The plus sign.

NumberFormatter::CURRENCY_SYMBOL (integer)
The currency symbol.

NumberFormatter::INTL_CURRENCY_SYMBOL (integer)
The international currency symbol.

NumberFormatter::MONETARY_SEPARATOR_SYMBOL (integer)
The monetary separator.

NumberFormatter::EXPONENTIAL_SYMBOL (integer)
The exponential symbol.

NumberFormatter::PERMILL_SYMBOL (integer)
Per mill symbol.

NumberFormatter::PAD_ESCAPE_SYMBOL (integer)
Escape padding character.

NumberFormatter::INFINITY_SYMBOL (integer)
Infinity symbol.

NumberFormatter::NAN_SYMBOL (integer)
Not-a-number symbol.

NumberFormatter::SIGNIFICANT_DIGIT_SYMBOL (integer)
Significant digit symbol.

NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL (integer)
The monetary grouping separator.

Rounding mode values used by numfmt_get_attribute and numfmt_set_attribute with NumberFormatter::ROUNDING_MODE attribute.

NumberFormatter::ROUND_CEILING (integer)
Rounding mode to round towards positive infinity.

NumberFormatter::ROUND_DOWN (integer)
Rounding mode to round towards zero.

NumberFormatter::ROUND_FLOOR (integer)
Rounding mode to round towards negative infinity.

NumberFormatter::ROUND_HALFDOWN (integer)
Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.

NumberFormatter::ROUND_HALFEVEN (integer)
Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.

NumberFormatter::ROUND_HALFUP (integer)
Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.

NumberFormatter::ROUND_UP (integer)
Rounding mode to round away from zero.

Pad position values used by numfmt_get_attribute and numfmt_set_attribute with NumberFormatter::PADDING_POSITION attribute.

NumberFormatter::PAD_AFTER_PREFIX (integer)
Pad characters inserted after the prefix.

NumberFormatter::PAD_AFTER_SUFFIX (integer)
Pad characters inserted after the suffix.

NumberFormatter::PAD_BEFORE_PREFIX (integer)
Pad characters inserted before the prefix.

NumberFormatter::PAD_BEFORE_SUFFIX (integer)
Pad characters inserted before the suffix.

参见

NumberFormatter::create

numfmt_create

NumberFormatter::__construct

Create a number formatter

说明

面向对象风格 (method)

public static NumberFormatter NumberFormatter::create ( string $locale , int $style [, string $pattern ] )

过程化风格

NumberFormatter numfmt_create ( string $locale , int $style [, string $pattern ] )

面向对象风格 (constructor):

public NumberFormatter::__construct ( string $locale , int $style [, string $pattern ] )

Creates a number formatter.

参数

locale
Locale in which the number would be formatted (locale name, e.g. en_CA).

style
Style of the formatting, one of the format style constants. If NumberFormatter::PATTERN_DECIMAL or NumberFormatter::PATTERN_RULEBASED is passed then the number format is opened using the given pattern, which must conform to the syntax described in » ICU DecimalFormat documentation or » ICU RuleBasedNumberFormat documentation, respectively.

pattern
Pattern string if the chosen style requires a pattern.

返回值

Returns NumberFormatter object or FALSE on error.

范例

示例 #1 numfmt_create example

<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
$fmt = numfmt_create( 'it', NumberFormatter::SPELLOUT );
echo numfmt_format($fmt, 1142)."\n";
?>

示例 #2 NumberFormatter::create example

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo $fmt->format(1234567.891234567890000)."\n";
$fmt = new NumberFormatter( 'it', NumberFormatter::SPELLOUT );
echo $fmt->format(1142)."\n";
?>

以上例程会输出:

1.234.567,891
millicentoquarantadue

参见

  • numfmt_format
  • numfmt_parse

NumberFormatter::formatCurrency

numfmt_format_currency

Format a currency value

说明

面向对象风格

public string NumberFormatter::formatCurrency ( float $value , string $currency )

过程化风格

string numfmt_format_currency ( NumberFormatter $fmt , float $value , string $currency )

Format the currency value according to the formatter rules.

参数

fmt
NumberFormatter object.

value
The numeric currency value.

currency
The 3-letter ISO 4217 currency code indicating the currency to use.

返回值

String representing the formatted currency value, 或者在失败时返回 FALSE.

范例

示例 #1 numfmt_format_currency example

<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::CURRENCY );
echo numfmt_format_currency($fmt, 1234567.891234567890000, "EUR")."\n";
echo numfmt_format_currency($fmt, 1234567.891234567890000, "RUR")."\n";
$fmt = numfmt_create( 'ru_RU', NumberFormatter::CURRENCY );
echo numfmt_format_currency($fmt, 1234567.891234567890000, "EUR")."\n";
echo numfmt_format_currency($fmt, 1234567.891234567890000, "RUR")."\n";
?>

示例 #2 OO example

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."\n";
$fmt = new NumberFormatter( 'ru_RU', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."\n";
?>

以上例程会输出:

1.234.567,89 €
1.234.567,89 RUR
1 234 567,89€
1 234 567,89р.

参见

  • numfmt_get_error_code
  • numfmt_format
  • numfmt_parse_currency

NumberFormatter::format

numfmt_format

Format a number

说明

面向对象风格

public string NumberFormatter::format ( number $value [, int $type ] )

过程化风格

string numfmt_format ( NumberFormatter $fmt , number $value [, int $type ] )

Format a numeric value according to the formatter rules.

参数

fmt
NumberFormatter object.

value
The value to format. Can be integer or float, other values will be converted to a numeric value.

type
The formatting type to use.

返回值

Returns the string containing formatted value, or FALSE on error.

范例

示例 #1 numfmt_format example

<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
$data = numfmt_format($fmt, 1234567.891234567890000);
if(intl_is_failure(numfmt_format($fmt))) {
    report_error("Formatter error");
}
?>

示例 #2 OO example

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
$fmt->format(1234567.891234567890000);
if(intl_is_failure($fmt->getErrorCode())) {
    report_error("Formatter error");
}
?>

以上例程会输出:

1.234.567,891

参见

  • numfmt_get_error_code
  • numfmt_format_currency
  • numfmt_parse

NumberFormatter::getAttribute

numfmt_get_attribute

Get an attribute

说明

面向对象风格

public int NumberFormatter::getAttribute ( int $attr )

过程化风格

int numfmt_get_attribute ( NumberFormatter $fmt , int $attr )

Get a numeric attribute associated with the formatter. An example of a numeric attribute is the number of integer digits the formatter will produce.

参数

fmt
NumberFormatter object.

attr
Attribute specifier - one of the numeric attribute constants.

返回值

Return attribute value on success, or FALSE on error.

范例

示例 #1 numfmt_get_attribute example

<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Digits: ".numfmt_get_attribute($fmt, NumberFormatter::MAX_FRACTION_DIGITS)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
numfmt_set_attribute($fmt, NumberFormatter::MAX_FRACTION_DIGITS, 2);
echo "Digits: ".numfmt_get_attribute($fmt, NumberFormatter::MAX_FRACTION_DIGITS)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
?>

示例 #2 OO example

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Digits: ".$fmt->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS)."\n";
echo $fmt->format(1234567.891234567890000)."\n";
$fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, 2);
echo "Digits: ".$fmt->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS)."\n";
echo $fmt->format(1234567.891234567890000)."\n";
?>

以上例程会输出:

Digits: 3
1.234.567,891
Digits: 2
1.234.567,89

参见

  • numfmt_get_error_code
  • numfmt_get_text_attribute
  • numfmt_set_attribute

NumberFormatter::getErrorCode

numfmt_get_error_code

Get formatter's last error code

说明

面向对象风格

public int NumberFormatter::getErrorCode ( void )

过程化风格

int numfmt_get_error_code ( NumberFormatter $fmt )

Get error code from the last function performed by the formatter.

参数

fmt
NumberFormatter object.

返回值

Returns error code from last formatter call.

范例

示例 #1 numfmt_get_error_code example

<?php
$fmt  = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
$data = numfmt_format($fmt, 1234567.891234567890000);
if(intl_is_failure(numfmt_get_error_code($fmt))) {
    report_error("Formatter error");
}
?>

示例 #2 OO example

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
$fmt->format(1234567.891234567890000);
if(intl_is_failure($fmt->getErrorCode())) {
    report_error("Formatter error");
}
?>

参见

  • numfmt_get_error_message
  • intl_get_error_code
  • intl_is_failure

NumberFormatter::getErrorMessage

numfmt_get_error_message

Get formatter's last error message

说明

面向对象风格

public string NumberFormatter::getErrorMessage ( void )

过程化风格

string numfmt_get_error_message ( NumberFormatter $fmt )

Get error message from the last function performed by the formatter.

参数

fmt
NumberFormatter object.

返回值

Returns error message from last formatter call.

范例

示例 #1 numfmt_get_error_message example

<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
$data = numfmt_format($fmt, 1234567.891234567890000);
var_dump(numfmt_get_error_message($fmt));
?>

示例 #2 OO example

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
$fmt->format(1234567.891234567890000);
var_dump(numfmt_get_error_message($fmt));
?>

参见

  • numfmt_get_error_code
  • intl_get_error_code
  • intl_is_failure

NumberFormatter::getLocale

numfmt_get_locale

Get formatter locale

说明

面向对象风格

public string NumberFormatter::getLocale ([ int $type ] )

过程化风格

string numfmt_get_locale ( NumberFormatter $fmt [, int $type ] )

Get formatter locale name.

参数

fmt
NumberFormatter object.

type
You can choose between valid and actual locale ( Locale::VALID_LOCALE, Locale::ACTUAL_LOCALE, respectively). The default is the actual locale.

返回值

The locale name used to create the formatter.

范例

示例 #1 numfmt_get_locale example

<?php
$req     = 'fr_FR_PARIS';
$fmt     = numfmt_create( $req,  NumberFormatter::DECIMAL);
$res_val = numfmt_get_locale( $fmt, Locale::VALID_LOCALE );
$res_act = numfmt_get_locale( $fmt, Locale::ACTUAL_LOCALE );
printf( "Requested locale name: %s\nValid locale name: %s\nActual locale name: %s\n",
         $req, $res_val, $res_act );
?>

以上例程会输出:

Requested locale name: fr_FR_PARIS
Valid locale name: fr_FR
Actual locale name: fr

参见

  • numfmt_create
  • numfmt_get_error_code

NumberFormatter::getPattern

numfmt_get_pattern

Get formatter pattern

说明

面向对象风格

public string NumberFormatter::getPattern ( void )

过程化风格

string numfmt_get_pattern ( NumberFormatter $fmt )

Extract pattern used by the formatter.

参数

fmt
NumberFormatter object.

返回值

Pattern string that is used by the formatter, or FALSE if an error happens.

范例

示例 #1 numfmt_get_pattern example

<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Pattern: ".numfmt_get_pattern($fmt)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
numfmt_set_pattern($fmt, "#0.# kg");
echo "Pattern: ".numfmt_get_pattern($fmt)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
?>

示例 #2 OO example

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Pattern: ".$fmt->getPattern()."\n";
echo $fmt->format(1234567.891234567890000)."\n";
$fmt->setPattern("#0.# kg");
echo "Pattern: ".$fmt->getPattern()."\n";
echo $fmt->format(1234567.891234567890000)."\n";
?>

以上例程会输出:

Pattern: #,##0.###
1.234.567,891
Pattern: #0.# kg
1234567,9 kg

参见

  • numfmt_get_error_code
  • numfmt_set_pattern
  • numfmt_create

NumberFormatter::getSymbol

numfmt_get_symbol

Get a symbol value

说明

面向对象风格

public string NumberFormatter::getSymbol ( int $attr )

过程化风格

string numfmt_get_symbol ( NumberFormatter $fmt , int $attr )

Get a symbol associated with the formatter. The formatter uses symbols to represent the special locale-dependent characters in a number, for example the percent sign. This API is not supported for rule-based formatters.

参数

fmt
NumberFormatter object.

attr
Symbol specifier, one of the format symbol constants.

返回值

The symbol string or FALSE on error.

范例

示例 #1 numfmt_get_symbol example

<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Sep: ".numfmt_get_symbol($fmt, NumberFormatter::GROUPING_SEPARATOR_SYMBOL)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
numfmt_set_symbol($fmt, NumberFormatter::GROUPING_SEPARATOR_SYMBOL, "*");
echo "Sep: ".numfmt_get_symbol($fmt, NumberFormatter::GROUPING_SEPARATOR_SYMBOL)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
?>

示例 #2 OO example

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Sep: ".$fmt->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL)."\n";
echo $fmt->format(1234567.891234567890000)."\n";
$fmt->setSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL, "*");
echo "Sep: ".$fmt->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL)."\n";
echo $fmt->format(1234567.891234567890000)."\n";
?>

以上例程会输出:

Sep: .
1.234.567,891
Sep: *
1*234*567,891

参见

  • numfmt_get_error_code
  • numfmt_set_symbol

NumberFormatter::getTextAttribute

numfmt_get_text_attribute

Get a text attribute

说明

面向对象风格

public string NumberFormatter::getTextAttribute ( int $attr )

过程化风格

string numfmt_get_text_attribute ( NumberFormatter $fmt , int $attr )

Get a text attribute associated with the formatter. An example of a text attribute is the suffix for positive numbers. If the formatter does not understand the attribute, U_UNSUPPORTED_ERROR error is produced. Rule-based formatters only understand NumberFormatter::DEFAULT_RULESET and NumberFormatter::PUBLIC_RULESETS.

参数

fmt
NumberFormatter object.

attr
Attribute specifier - one of the text attribute constants.

返回值

Return attribute value on success, or FALSE on error.

范例

示例 #1 numfmt_get_text_attribute example

<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Prefix: ".numfmt_get_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX)."\n";
echo numfmt_format($fmt, -1234567.891234567890000)."\n";
numfmt_set_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX, "MINUS");
echo "Prefix: ".numfmt_get_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX)."\n";
echo numfmt_format($fmt, -1234567.891234567890000)."\n";
?>

示例 #2 OO example

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Prefix: ".$fmt->getTextAttribute(NumberFormatter::NEGATIVE_PREFIX)."\n";
echo $fmt->format(-1234567.891234567890000)."\n";
$fmt->setTextAttribute(NumberFormatter::NEGATIVE_PREFIX, "MINUS");
echo "Prefix: ".$fmt->getTextAttribute(NumberFormatter::NEGATIVE_PREFIX)."\n";
echo $fmt->format(-1234567.891234567890000)."\n";
?>

以上例程会输出:

Prefix: -
-1.234.567,891
Prefix: MINUS
MINUS1.234.567,891

参见

  • numfmt_get_error_code
  • numfmt_get_attribute
  • numfmt_set_text_attribute

NumberFormatter::parseCurrency

numfmt_parse_currency

Parse a currency number

说明

面向对象风格

public float NumberFormatter::parseCurrency ( string $value , string &$currency [, int &$position ] )

过程化风格

float numfmt_parse_currency ( NumberFormatter $fmt , string $value , string &$currency [, int &$position ] )

Parse a string into a double and a currency using the current formatter.

参数

fmt
NumberFormatter object.

currency
Parameter to receive the currency name (3-letter ISO 4217 currency code).

position
Offset in the string at which to begin parsing. On return, this value will hold the offset at which parsing ended.

返回值

The parsed numeric value or FALSE on error.

范例

示例 #1 numfmt_parse_currency example

<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::CURRENCY );
$num = "1.234.567,89\xc2\xa0$";
echo "We have ".numfmt_parse_currency($fmt, $num, $curr)." in $curr\n";
?>

示例 #2 OO example

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
$num = "1.234.567,89\xc2\xa0$";
echo "We have ".$fmt->parseCurrency($num, $curr)." in $curr\n";
?>

以上例程会输出:

We have 1234567.89 in USD

参见

  • numfmt_get_error_code
  • numfmt_parse
  • numfmt_format_currency

NumberFormatter::parse

numfmt_parse

Parse a number

说明

面向对象风格

public mixed NumberFormatter::parse ( string $value [, int $type [, int &$position ]] )

过程化风格

mixed numfmt_parse ( NumberFormatter $fmt , string $value [, int $type [, int &$position ]] )

Parse a string into a number using the current formatter rules.

参数

fmt
NumberFormatter object.

type
The formatting type to use. By default, NumberFormatter::TYPE_DOUBLE is used.

position
Offset in the string at which to begin parsing. On return, this value will hold the offset at which parsing ended.

返回值

The value of the parsed number or FALSE on error.

范例

示例 #1 numfmt_parse example

<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
$num = "1.234.567,891";
echo numfmt_parse($fmt, $num)."\n";
echo numfmt_parse($fmt, $num, NumberFormatter::TYPE_INT32)."\n";
?>

示例 #2 OO example

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
$num = "1.234.567,891";
echo $fmt->parse($num)."\n";
echo $fmt->parse($num, NumberFormatter::TYPE_INT32)."\n";
?>

以上例程会输出:

1234567.891
1234567

参见

  • numfmt_get_error_code
  • numfmt_format
  • numfmt_parse_currency

NumberFormatter::setAttribute

numfmt_set_attribute

Set an attribute

说明

面向对象风格

public bool NumberFormatter::setAttribute ( int $attr , int $value )

过程化风格

bool numfmt_set_attribute ( NumberFormatter $fmt , int $attr , int $value )

Set a numeric attribute associated with the formatter. An example of a numeric attribute is the number of integer digits the formatter will produce.

参数

fmt
NumberFormatter object.

attr
Attribute specifier - one of the numeric attribute constants.

value
The attribute value.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 numfmt_set_attribute example

<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Digits: ".numfmt_get_attribute($fmt, NumberFormatter::MAX_FRACTION_DIGITS)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
numfmt_set_attribute($fmt, NumberFormatter::MAX_FRACTION_DIGITS, 2);
echo "Digits: ".numfmt_get_attribute($fmt, NumberFormatter::MAX_FRACTION_DIGITS)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
?>

示例 #2 OO example

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Digits: ".$fmt->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS)."\n";
echo $fmt->format(1234567.891234567890000)."\n";
$fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, 2);
echo "Digits: ".$fmt->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS)."\n";
echo $fmt->format(1234567.891234567890000)."\n";
?>

以上例程会输出:

Digits: 3
1.234.567,891
Digits: 2
1.234.567,89

参见

  • numfmt_get_error_code
  • numfmt_get_attribute
  • numfmt_set_text_attribute

NumberFormatter::setPattern

numfmt_set_pattern

Set formatter pattern

说明

面向对象风格

public bool NumberFormatter::setPattern ( string $pattern )

过程化风格

bool numfmt_set_pattern ( NumberFormatter $fmt , string $pattern )

Set the pattern used by the formatter. Can not be used on a rule-based formatter.

参数

fmt
NumberFormatter object.

pattern
Pattern in syntax described in » ICU DecimalFormat documentation.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 numfmt_set_pattern example

<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Pattern: ".numfmt_get_pattern($fmt)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
numfmt_set_pattern($fmt, "#0.# kg");
echo "Pattern: ".numfmt_get_pattern($fmt)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
?>

示例 #2 OO example

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Pattern: ".$fmt->getPattern()."\n";
echo $fmt->format(1234567.891234567890000)."\n";
$fmt->setPattern("#0.# kg");
echo "Pattern: ".$fmt->getPattern()."\n";
echo $fmt->format(1234567.891234567890000)."\n";
?>

以上例程会输出:

Pattern: #,##0.###
1.234.567,891
Pattern: #0.# kg
1234567,9 kg

参见

  • numfmt_get_error_code
  • numfmt_create
  • numfmt_get_pattern

NumberFormatter::setSymbol

numfmt_set_symbol

Set a symbol value

说明

面向对象风格

public bool NumberFormatter::setSymbol ( int $attr , string $value )

过程化风格

bool numfmt_set_symbol ( NumberFormatter $fmt , int $attr , string $value )

Set a symbol associated with the formatter. The formatter uses symbols to represent the special locale-dependent characters in a number, for example the percent sign. This API is not supported for rule-based formatters.

参数

fmt
NumberFormatter object.

attr
Symbol specifier, one of the format symbol constants.

value
Text for the symbol.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 numfmt_set_symbol example

<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Sep: ".numfmt_get_symbol($fmt, NumberFormatter::GROUPING_SEPARATOR_SYMBOL)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
numfmt_set_symbol($fmt, NumberFormatter::GROUPING_SEPARATOR_SYMBOL, "*");
echo "Sep: ".numfmt_get_symbol($fmt, NumberFormatter::GROUPING_SEPARATOR_SYMBOL)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
?>

示例 #2 OO example

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Sep: ".$fmt->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL)."\n";
echo $fmt->format(1234567.891234567890000)."\n";
$fmt->setSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL, "*");
echo "Sep: ".$fmt->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL)."\n";
echo $fmt->format(1234567.891234567890000)."\n";
?>

以上例程会输出:

Sep: .
1.234.567,891
Sep: *
1*234*567,891

参见

  • numfmt_get_error_code
  • numfmt_get_symbol

NumberFormatter::setTextAttribute

numfmt_set_text_attribute

Set a text attribute

说明

面向对象风格

public bool NumberFormatter::setTextAttribute ( int $attr , string $value )

过程化风格

bool numfmt_set_text_attribute ( NumberFormatter $fmt , int $attr , string $value )

Set a text attribute associated with the formatter. An example of a text attribute is the suffix for positive numbers. If the formatter does not understand the attribute, U_UNSUPPORTED_ERROR error is produced. Rule-based formatters only understand NumberFormatter::DEFAULT_RULESET and NumberFormatter::PUBLIC_RULESETS.

参数

fmt
NumberFormatter object.

attr
Attribute specifier - one of the text attribute constants.

value
Text for the attribute value.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 numfmt_set_text_attribute example

<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Prefix: ".numfmt_get_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX)."\n";
echo numfmt_format($fmt, -1234567.891234567890000)."\n";
numfmt_set_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX, "MINUS");
echo "Prefix: ".numfmt_get_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX)."\n";
echo numfmt_format($fmt, -1234567.891234567890000)."\n";
?>

示例 #2 OO example

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Prefix: ".$fmt->getTextAttribute(NumberFormatter::NEGATIVE_PREFIX)."\n";
echo $fmt->format(-1234567.891234567890000)."\n";
$fmt->setTextAttribute(NumberFormatter::NEGATIVE_PREFIX, "MINUS");
echo "Prefix: ".$fmt->getTextAttribute(NumberFormatter::NEGATIVE_PREFIX)."\n";
echo $fmt->format(-1234567.891234567890000)."\n";
?>

以上例程会输出:

Prefix: -
-1.234.567,891
Prefix: MINUS
MINUS1.234.567,891

参见

  • numfmt_get_error_code
  • numfmt_get_text_attribute
  • numfmt_set_attribute

简介

A "Locale" is an identifier used to get language, culture, or regionally-specific behavior from an API. PHP locales are organized and identified the same way that the CLDR locales used by ICU (and many vendors of Unix-like operating systems, the Mac, Java, and so forth) use. Locales are identified using RFC 4646 language tags (which use hyphen, not underscore) in addition to the more traditional underscore-using identifiers. Unless otherwise noted the functions in this class are tolerant of both formats.

Examples of identifiers include:

  • en-US (English, United States)
  • zh-Hant-TW (Chinese, Traditional Script, Taiwan)
  • fr-CA, fr-FR (French for Canada and France respectively)

The Locale class (and related procedural functions) are used to interact with locale identifiers--to verify that an ID is well-formed, valid, etc. The extensions used by CLDR in UAX #35 (and inherited by ICU) are valid and used wherever they would be in ICU normally.

Locales cannot be instantiated as objects. All of the functions/methods provided are static.

The null or empty string obtains the "root" locale. The "root" locale is equivalent to "en_US_POSIX" in CLDR. Language tags (and thus locale identifiers) are case insensitive. There exists a canonicalization function to make case match the specification.

类摘要

Locale

class Locale {

/* 方法 */

public static string acceptFromHttp ( string $header )

public static string canonicalize ( string $locale )

public static string composeLocale ( array $subtags )

public static bool filterMatches ( string $langtag , string $locale [, bool $canonicalize = FALSE ] )

public static array getAllVariants ( string $locale )

public static string getDefault ( void )

public static string getDisplayLanguage ( string $locale [, string $in_locale ] )

public static string getDisplayName ( string $locale [, string $in_locale ] )

public static string getDisplayRegion ( string $locale [, string $in_locale ] )

public static string getDisplayScript ( string $locale [, string $in_locale ] )

public static string getDisplayVariant ( string $locale [, string $in_locale ] )

public static array getKeywords ( string $locale )

public static string getPrimaryLanguage ( string $locale )

public static string getRegion ( string $locale )

public static string getScript ( string $locale )

public static string lookup ( array $langtag , string $locale [, bool $canonicalize = FALSE [, string $default ]] )

public static array parseLocale ( string $locale )

public static bool setDefault ( string $locale )

}

预定义常量

Locale::DEFAULT_LOCALE (null)
Used as locale parameter with the methods of the various locale affected classes, such as NumberFormatter. This constant would make the methods to use default locale.

These constants describe the choice of the locale for the getLocale method of different classes.

Locale::ACTUAL_LOCALE (string)
This is locale the data actually comes from.

Locale::VALID_LOCALE (string)
This is the most specific locale supported by ICU.

These constants define how the Locales are parsed or composed. They should be used as keys in the argument array to locale_compose and are returned from locale_parse as keys of the returned associative array.

Locale::LANG_TAG (string)
Language subtag

Locale::EXTLANG_TAG (string)
Extended language subtag

Locale::SCRIPT_TAG (string)
Script subtag

Locale::REGION_TAG (string)
Region subtag

Locale::VARIANT_TAG (string)
Variant subtag

Locale::GRANDFATHERED_LANG_TAG (string)
Grandfathered Language subtag

Locale::PRIVATE_TAG (string)
Private subtag

参见

Locale::acceptFromHttp

locale_accept_from_http

Tries to find out best available locale based on HTTP "Accept-Language" header

说明

面向对象风格

public static string Locale::acceptFromHttp ( string $header )

过程化风格

string locale_accept_from_http ( string $header )

Tries to find locale that can satisfy the language list that is requested by the HTTP "Accept-Language" header.

参数

header
The string containing the "Accept-Language" header according to format in RFC 2616.

返回值

The corresponding locale identifier.

范例

示例 #1 locale_accept_from_http example

<?php
$locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
echo $locale;
?>

示例 #2 OO example

<?php
$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
echo $locale;
?>

以上例程会输出:

en_US

参见

  • locale_lookup

Locale::canonicalize

locale_canonicalize

Canonicalize the locale string

说明

public static string Locale::canonicalize ( string $locale )

Warning

本函数还未编写文档,仅有参数列表。

参数

locale

返回值

Locale::composeLocale

locale_compose

Returns a correctly ordered and delimited locale ID

说明

面向对象风格

public static string Locale::composeLocale ( array $subtags )

过程化风格

string locale_compose ( array $subtags )

Returns a correctly ordered and delimited locale ID the keys identify the particular locale ID subtags, and the values are the associated subtag values.

参数

subtags
an array containing a list of key-value pairs, where the keys identify the particular locale ID subtags, and the values are the associated subtag values.

Note:

The 'variant' and 'private' subtags can take maximum 15 values whereas 'extlang' can take maximum 3 values.e.g. Variants are allowed with the suffix ranging from 0-14. Hence the keys for the input array can be variant0, variant1, ...,variant14. In the returned locale id, the subtag is ordered by suffix resulting in variant0 followed by variant1 followed by variant2 and so on.

The 'variant', 'private' and 'extlang' multiple values can be specified both as array under specific key (e.g. 'variant') and as multiple numbered keys (e.g. 'variant0', 'variant1', etc.).

返回值

The corresponding locale identifier.

范例

示例 #1 locale_compose example

<?php
$arr = array(
    'language'=>'en' ,
    'script'  =>'Hans' ,
    'region'  =>'CN',
    'variant2'=>'rozaj' ,
    'variant1'=>'nedis' ,
    'private1'=>'prv1' ,
    'private2'=>'prv2'
);
echo locale_compose( $arr );
?>

示例 #2 OO example

<?php
$arr = array(
    'language'=>'en' ,
    'script'  =>'Hans' ,
    'region'  =>'CN',
    'variant2'=>'rozaj' ,
    'variant1'=>'nedis' ,
    'private1'=>'prv1' ,
    'private2'=>'prv2'
);
echo Locale::composeLocale( $arr );
?>

以上例程会输出:

Locale: en_Hans_CN_nedis_rozaj_x_prv1_prv2

参见

  • locale_parse

Locale::filterMatches

locale_filter_matches

Checks if a language tag filter matches with locale

说明

面向对象风格

public static bool Locale::filterMatches ( string $langtag , string $locale [, bool $canonicalize = FALSE ] )

过程化风格

bool locale_filter_matches ( string $langtag , string $locale [, bool $canonicalize = FALSE ] )

Checks if a $langtag filter matches with $locale according to RFC 4647's basic filtering algorithm

参数

langtag
The language tag to check

locale
The language range to check against

canonicalize
If true, the arguments will be converted to canonical form before matching.

返回值

TRUE if $locale matches $langtag FALSE otherwise.

范例

示例 #1 locale_filter_matches example

<?php
echo (locale_filter_matches('de-DEVA','de-DE', false)) ? "Matches" : "Does not match"; 
echo '; ';
echo (locale_filter_matches('de-DE_1996','de-DE', false)) ? "Matches" : "Does not match"; 
?>

示例 #2 OO example

<?php
echo (Locale::filterMatches('de-DEVA','de-DE', false)) ? "Matches" : "Does not match"; 
echo '; ';
echo (Locale::filterMatches('de-DE-1996','de-DE', false)) ? "Matches" : "Does not match"; 
?>

以上例程会输出:

Does not match; Matches

参见

  • locale_lookup

Locale::getAllVariants

locale_get_all_variants

Gets the variants for the input locale

说明

面向对象风格

public static array Locale::getAllVariants ( string $locale )

过程化风格

array locale_get_all_variants ( string $locale )

Gets the variants for the input locale

参数

locale
The locale to extract the variants from

返回值

The array containing the list of all variants subtag for the locale or NULL if not present

范例

示例 #1 locale_get_all_variants example

<?php
$arr = locale_get_all_variants('sl_IT_NEDIS_ROJAZ_1901');
var_export( $arr );
?>

示例 #2 OO example

<?php
 $arr = Locale::getAllVariants('sl_IT_NEDIS_ROJAZ_1901');
 var_export( $arr );
?>

以上例程会输出:

array (
    0 => 'NEDIS',
    1 => 'ROJAZ',
    2 => '1901',
)

参见

  • locale_get_primary_language
  • locale_get_script
  • locale_get_region

Locale::getDefault

locale_get_default

Gets the default locale value from the INTL global 'default_locale'

说明

面向对象风格

public static string Locale::getDefault ( void )

过程化风格

string locale_get_default ( void )

Gets the default locale value. At the PHP initialization this value is set to 'intl.default_locale' value from php.ini if that value exists or from ICU's function uloc_getDefault().

参数

返回值

The current runtime locale

范例

示例 #1 locale_get_default example

<?php
ini_set('intl.default_locale', 'de-DE');
echo locale_get_default();
echo '; ';
locale_set_default('fr');
echo locale_get_default();
?>

示例 #2 OO example

<?php
ini_set('intl.default_locale', 'de-DE');
echo Locale::getDefault();
echo '; ';
Locale::setDefault('fr');
echo Locale::getDefault();
?>

以上例程会输出:

de-DE; fr

参见

  • locale_set_default

Locale::getDisplayLanguage

locale_get_display_language

Returns an appropriately localized display name for language of the inputlocale

说明

面向对象风格

public static string Locale::getDisplayLanguage ( string $locale [, string $in_locale ] )

过程化风格

string locale_get_display_language ( string $locale [, string $in_locale ] )

Returns an appropriately localized display name for language of the input locale. If is NULL then the default locale is used.

参数

locale
The locale to return a display language for

in_locale
Optional format locale to use to display the language name

返回值

display name of the language for the $locale in the format appropriate for $in_locale.

范例

示例 #1 locale_get_display_language example

<?php
echo locale_get_display_language('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo locale_get_display_language('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo locale_get_display_language('sl-Latn-IT-nedis', 'de');
?>

示例 #2 OO example

<?php
echo Locale::getDisplayLanguage('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo Locale::getDisplayLanguage('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo Locale::getDisplayLanguage('sl-Latn-IT-nedis', 'de');
?>

以上例程会输出:

Slovenian;
slov\xc3\xa8ne;
Slowenisch

参见

  • locale_get_display_name
  • locale_get_display_script
  • locale_get_display_region
  • locale_get_display_variant

Locale::getDisplayName

locale_get_display_name

Returns an appropriately localized display name for the input locale

说明

面向对象风格

public static string Locale::getDisplayName ( string $locale [, string $in_locale ] )

过程化风格

string locale_get_display_name ( string $locale [, string $in_locale ] )

Returns an appropriately localized display name for the input locale. If $locale is NULL then the default locale is used.

参数

locale
The locale to return a display name for.

in_locale
optional format locale

返回值

Display name of the locale in the format appropriate for $in_locale.

范例

示例 #1 locale_get_display_name example

<?php
echo locale_get_display_name('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo locale_get_display_name('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo locale_get_display_name('sl-Latn-IT-nedis', 'de');
?>

示例 #2 OO example

<?php
echo Locale::getDisplayName('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo Locale::getDisplayName('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo Locale::getDisplayName('sl-Latn-IT-nedis', 'de');
?>

以上例程会输出:

Slovenian (Latin, Italy, Natisone dialect);
slov\xc3\xa8ne (latin, Italie, dialecte de Natisone;
Slowenisch (Lateinisch, Italien, NEDIS)

参见

  • locale_get_display_language
  • locale_get_display_script
  • locale_get_display_region
  • locale_get_display_variant

Locale::getDisplayRegion

locale_get_display_region

Returns an appropriately localized display name for region of the input locale

说明

面向对象风格

public static string Locale::getDisplayRegion ( string $locale [, string $in_locale ] )

过程化风格

string locale_get_display_region ( string $locale [, string $in_locale ] )

Returns an appropriately localized display name for region of the input locale. If is NULL then the default locale is used.

参数

locale
The locale to return a display region for.

in_locale
Optional format locale to use to display the region name

返回值

display name of the region for the $locale in the format appropriate for $in_locale.

范例

示例 #1 locale_get_display_region example

<?php
echo locale_get_display_region('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo locale_get_display_region('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo locale_get_display_region('sl-Latn-IT-nedis', 'de');
?>

示例 #2 OO example

<?php
echo Locale::getDisplayRegion('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo Locale::getDisplayRegion('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo Locale::getDisplayRegion('sl-Latn-IT-nedis', 'de');
?>

以上例程会输出:

Italy;
Italie;
Italien

参见

  • locale_get_display_name
  • locale_get_display_language
  • locale_get_display_script
  • locale_get_display_variant

Locale::getDisplayScript

locale_get_display_script

Returns an appropriately localized display name for script of the input locale

说明

面向对象风格

public static string Locale::getDisplayScript ( string $locale [, string $in_locale ] )

过程化风格

string locale_get_display_script ( string $locale [, string $in_locale ] )

Returns an appropriately localized display name for script of the input locale. If is NULL then the default locale is used.

参数

locale
The locale to return a display script for

in_locale
Optional format locale to use to display the script name

返回值

Display name of the script for the $locale in the format appropriate for $in_locale.

范例

示例 #1 locale_get_display_script example

<?php
echo locale_get_display_script('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo locale_get_display_script('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo locale_get_display_script('sl-Latn-IT-nedis', 'de');
?>

示例 #2 OO example

<?php
echo Locale::getDisplayScript('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo Locale::getDisplayScript('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo Locale::getDisplayScript('sl-Latn-IT-nedis', 'de');
?>

以上例程会输出:

Latin;
latin;
Lateinisch

参见

  • locale_get_display_name
  • locale_get_display_language
  • locale_get_display_region
  • locale_get_display_variant

Locale::getDisplayVariant

locale_get_display_variant

Returns an appropriately localized display name for variants of the input locale

说明

面向对象风格

public static string Locale::getDisplayVariant ( string $locale [, string $in_locale ] )

过程化风格

string locale_get_display_variant ( string $locale [, string $in_locale ] )

Returns an appropriately localized display name for variants of the input locale. If is NULL then the default locale is used.

参数

locale
The locale to return a display variant for

in_locale
Optional format locale to use to display the variant name

返回值

Display name of the variant for the $locale in the format appropriate for $in_locale.

范例

示例 #1 locale_get_display_variant example

<?php
echo locale_get_display_variant('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo locale_get_display_variant('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo locale_get_display_variant('sl-Latn-IT-nedis', 'de');
?>

示例 #2 OO example

<?php
echo Locale::getDisplayVariant('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo Locale::getDisplayVariant('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo Locale::getDisplayVariant('sl-Latn-IT-nedis', 'de');
?>

以上例程会输出:

Natisone dialect;
dialecte de Natisone;
NEDIS

参见

  • locale_get_display_name
  • locale_get_display_language
  • locale_get_display_script
  • locale_get_display_region

Locale::getKeywords

locale_get_keywords

Gets the keywords for the input locale

说明

面向对象风格

public static array Locale::getKeywords ( string $locale )

过程化风格

array locale_get_keywords ( string $locale )

Gets the keywords for the input locale.

参数

locale
The locale to extract the keywords from

返回值

Associative array containing the keyword-value pairs for this locale

范例

示例 #1 locale_get_keywords example

<?php
$keywords_arr = locale_get_keywords( 'de_DE@currency=EUR;collation=PHONEBOOK' );
if ($keywords_arr) {
    foreach ($keywords_arr as $key => $value) {
        echo "$key = $value\n"; 
    }
}
?>

示例 #2 OO example

<?php
$keywords_arr = Locale::getKeywords( 'de_DE@currency=EUR;collation=PHONEBOOK' );
if ($keywords_arr) {
    foreach( $keywords_arr as $key => $value){
        echo "$key = $value\n"; 
    }
}
?>

以上例程会输出:

collation = PHONEBOOK
currency = EUR

参见

  • locale_get_all_variants

Locale::getPrimaryLanguage

locale_get_primary_language

Gets the primary language for the input locale

说明

面向对象风格

public static string Locale::getPrimaryLanguage ( string $locale )

过程化风格

string locale_get_primary_language ( string $locale )

Gets the primary language for the input locale

参数

locale
The locale to extract the primary language code from

返回值

The language code associated with the language or NULL in case of error.

范例

示例 #1 locale_get_primary_language example

<?php
echo locale_get_primary_language('zh-Hant');
?>

示例 #2 OO example

<?php
echo Locale::getPrimaryLanguage('zh-Hant');
?>

以上例程会输出:

zh

参见

  • locale_get_script
  • locale_get_region
  • locale_get_all_variants

Locale::getRegion

locale_get_region

Gets the region for the input locale

说明

面向对象风格

public static string Locale::getRegion ( string $locale )

过程化风格

string locale_get_region ( string $locale )

Gets the region for the input locale.

参数

locale
The locale to extract the region code from

返回值

The region subtag for the locale or NULL if not present

范例

示例 #1 locale_get_region example

<?php
echo locale_get_region('de-CH-1901');
?>

示例 #2 OO example

<?php
echo Locale::getRegion('de-CH-1901');
?>

以上例程会输出:

CH

参见

  • locale_get_primary_language
  • locale_get_script
  • locale_get_all_variants

Locale::getScript

locale_get_script

Gets the script for the input locale

说明

面向对象风格

public static string Locale::getScript ( string $locale )

过程化风格

string locale_get_script ( string $locale )

Gets the script for the input locale.

参数

locale
The locale to extract the script code from

返回值

The script subtag for the locale or NULL if not present

范例

示例 #1 locale_get_script example

<?php
echo locale_get_script('sr-Cyrl');
?>

示例 #2 OO example

<?php
echo Locale::getScript('sr-Cyrl');
?>

以上例程会输出:

Cyrl

参见

  • locale_get_primary_language
  • locale_get_region
  • locale_get_all_variants

Locale::lookup

locale_lookup

Searches the language tag list for the best match to the language

说明

面向对象风格

public static string Locale::lookup ( array $langtag , string $locale [, bool $canonicalize = FALSE [, string $default ]] )

过程化风格

string locale_lookup ( array $langtag , string $locale [, bool $canonicalize = FALSE [, string $default ]] )

Searches the items in langtag for the best match to the language range specified in locale according to RFC 4647's lookup algorithm.

参数

langtag
An array containing a list of language tags to compare to locale. Maximum 100 items allowed.

locale
The locale to use as the language range when matching.

canonicalize
If true, the arguments will be converted to canonical form before matching.

default
The locale to use if no match is found.

返回值

The closest matching language tag or default value.

范例

示例 #1 locale_lookup example

<?php
$arr = array(
    'de-DEVA',
    'de-DE-1996',
    'de',
    'de-De'
);
echo locale_lookup($arr, 'de-DE-1996-x-prv1-prv2', true, 'en_US');
?>

示例 #2 OO example

<?php
$arr = array(
    'de-DEVA',
    'de-DE-1996',
    'de',
    'de-De'
);
echo Locale::lookup($arr, 'de-DE-1996-x-prv1-prv2', true, 'en_US');
?>

以上例程会输出:

de_de_1996

参见

  • locale_filter_matches

Locale::parseLocale

locale_parse

Returns a key-value array of locale ID subtag elements

说明

面向对象风格

public static array Locale::parseLocale ( string $locale )

过程化风格

array locale_parse ( string $locale )

Returns a key-value array of locale ID subtag elements.

参数

locale
The locale to extract the subtag array from. Note: The 'variant' and 'private' subtags can take maximum 15 values whereas 'extlang' can take maximum 3 values.

返回值

Returns an array containing a list of key-value pairs, where the keys identify the particular locale ID subtags, and the values are the associated subtag values. The array will be ordered as the locale id subtags e.g. in the locale id if variants are '-varX-varY-varZ' then the returned array will have variant0=>varX , variant1=>varY , variant2=>varZ

Returns NULL when the length of locale exceeds INTL_MAX_LOCALE_LEN.

范例

示例 #1 locale_parse example

<?php
$arr = locale_parse('sl-Latn-IT-nedis');
if ($arr) {
    foreach ($arr as $key => $value) {
        echo "$key : $value , ";
    }
}
?>

示例 #2 OO example

<?php
$arr = Locale::parseLocale('sl-Latn-IT-nedis');
if ($arr) {
    foreach ($arr as $key => $value) {
        echo "$key : $value , ";
    }
}
?>

以上例程会输出:

language : sl , script : Latn , region : IT , variant0 : NEDIS ,

参见

  • locale_compose

Locale::setDefault

locale_set_default

Sets the default runtime locale

说明

面向对象风格

public static bool Locale::setDefault ( string $locale )

过程化风格

bool locale_set_default ( string $locale )

Sets the default runtime locale to $locale. This changes the value of INTL global 'default_locale' locale identifier. UAX #35 extensions are accepted.

参数

locale
Is a BCP 47 compliant language tag.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 locale_set_default example

<?php
locale_set_default('de-DE');
echo locale_get_default();
?>

示例 #2 OO example

<?php
Locale::setDefault('de-DE');
echo Locale::getDefault();
?>

以上例程会输出:

de-DE

参见

  • locale_get_default

简介

Normalization is a process that involves transforming characters and sequences of characters into a formally-defined underlying representation. This process is most important when text needs to be compared for sorting and searching, but it is also used when storing text to ensure that the text is stored in a consistent representation.

The Unicode Consortium has defined a number of normalization forms reflecting the various needs of applications:

  • Normalization Form D (NFD) - Canonical Decomposition
  • Normalization Form C (NFC) - Canonical Decomposition followed by Canonical Composition
  • Normalization Form KD (NFKD) - Compatibility Decomposition
  • Normalization Form KC (NFKC) - Compatibility Decomposition followed by Canonical Composition

The different forms are defined in terms of a set of transformations on the text, transformations that are expressed by both an algorithm and a set of data files.

类摘要

Normalizer

class Normalizer {

/* 方法 */

public static string getRawDecomposition ( string $input )

public static bool isNormalized ( string $input [, int $form = Normalizer::FORM_C ] )

public static string normalize ( string $input [, int $form = Normalizer::FORM_C ] )

}

预定义常量

The following constants define the normalization form used by the normalizer:

Normalizer::FORM_C (integer)
Normalization Form C (NFC) - Canonical Decomposition followed by Canonical Composition

Normalizer::FORM_D (integer)
Normalization Form D (NFD) - Canonical Decomposition

Normalizer::FORM_KC (integer)
Normalization Form KC (NFKC) - Compatibility Decomposition, followed by Canonical Composition

Normalizer::FORM_KD (integer)
Normalization Form KD (NFKD) - Compatibility Decomposition

Normalizer::NONE (integer)
No decomposition/composition

Normalizer::OPTION_DEFAULT (integer)
Default normalization options

参见

Normalizer::getRawDecomposition

normalizer_get_raw_decomposition

Gets the Decomposition_Mapping property for the given UTF-8 encoded code point

说明

面向对象风格

public static string Normalizer::getRawDecomposition ( string $input )

过程化风格

string normalizer_get_raw_decomposition ( string $input )

Gets the Decomposition_Mapping property, as specified in the Unicode Character Database (UCD), for the given UTF-8 encoded code point.

参数

input
The input string, which should be a single, UTF-8 encoded, code point.

返回值

Returns a string containing the Decomposition_Mapping property, if present in the UCD.

Returns NULL if there is no Decomposition_Mapping property for the character.

范例

示例 #1 Normalizer::getRawDecomposition example

<?php

$result = "";
$strings = [
    "a",
    "\u{FFDA}",
    "\u{FDFA}",
    "",
    "aa",
    "\xF5",
];

foreach ($strings as $string) {
    $decomposition = Normalizer::getRawDecomposition($string);
    // $decomposition = normalizer_get_raw_decomposition($string); Procedural way

    $error_code = intl_get_error_code();
    $error_message = intl_get_error_message();

    $string_hex = bin2hex($string);
    $result .= "---------------------\n";

    if ($decomposition === null) {
        $result .= "'$string_hex' has no decomposition mapping\n" ;
    } else {
        $result .= "'$string_hex' has the decomposition mapping '" . bin2hex($decomposition) . "'\n" ;
    }

    $result .= "error info: '$error_message' ($error_code)\n";
}

echo $result;
?>

以上例程会输出:

---------------------
'61' has no decomposition mapping
error info: 'U_ZERO_ERROR' (0)
---------------------
'efbf9a' has the decomposition mapping 'e385a1'
error info: 'U_ZERO_ERROR' (0)
---------------------
'efb7ba' has the decomposition mapping 'd8b5d984d98920d8a7d984d984d98720d8b9d984d98ad98720d988d8b3d984d985'
error info: 'U_ZERO_ERROR' (0)
---------------------
'' has no decomposition mapping
error info: 'Input string must be exactly one UTF-8 encoded code point long.: U_ILLEGAL_ARGUMENT_ERROR' (1)
---------------------
'6161' has no decomposition mapping
error info: 'Input string must be exactly one UTF-8 encoded code point long.: U_ILLEGAL_ARGUMENT_ERROR' (1)
---------------------
'f5' has no decomposition mapping
error info: 'Code point out of range: U_ILLEGAL_ARGUMENT_ERROR' (1)

参见

  • Normalizer::normalize
  • Normalizer::isNormalized

Normalizer::isNormalized

normalizer_is_normalized

Checks if the provided string is already in the specified normalization form

说明

面向对象风格

public static bool Normalizer::isNormalized ( string $input [, int $form = Normalizer::FORM_C ] )

过程化风格

bool normalizer_is_normalized ( string $input [, int $form = Normalizer::FORM_C ] )

Checks if the provided string is already in the specified normalization form.

参数

input
The input string to normalize

form
One of the normalization forms.

返回值

TRUE if normalized, FALSE otherwise or if there an error

范例

示例 #1 normalizer_is_normalized example

<?php
$char_A_ring = "\xC3\x85"; // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5)
$char_combining_ring_above = "\xCC\x8A";  // 'COMBINING RING ABOVE' (U+030A)
 
$char_orig = 'A' . $char_combining_ring_above;
$char_norm = normalizer_normalize( 'A' . $char_combining_ring_above, Normalizer::FORM_C );
 
echo ( normalizer_is_normalized($char_orig, Normalizer::FORM_C) ) ? "normalized" : "not normalized";
echo '; ';
echo ( normalizer_is_normalized($char_norm, Normalizer::FORM_C) ) ? "normalized" : "not normalized";
?>

示例 #2 OO example

<?php
$char_A_ring = "\xC3\x85"; // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5)
$char_combining_ring_above = "\xCC\x8A";  // 'COMBINING RING ABOVE' (U+030A)
 
$char_orig = 'A' . $char_combining_ring_above;
$char_norm = Normalizer::normalize( 'A' . $char_combining_ring_above, Normalizer::FORM_C );
 
echo ( Normalizer::isNormalized($char_orig, Normalizer::FORM_C) ) ? "normalized" : "not normalized";
echo '; ';
echo ( Normalizer::isNormalized($char_norm, Normalizer::FORM_C) ) ? "normalized" : "not normalized";
?>

以上例程会输出:

not normalized; normalized

参见

  • normalizer_normalize

Normalizer::normalize

normalizer_normalize

Normalizes the input provided and returns the normalized string

说明

面向对象风格

public static string Normalizer::normalize ( string $input [, int $form = Normalizer::FORM_C ] )

过程化风格

string normalizer_normalize ( string $input [, int $form = Normalizer::FORM_C ] )

Normalizes the input provided and returns the normalized string

参数

input
The input string to normalize

form
One of the normalization forms.

返回值

The normalized string or FALSE if an error occurred.

范例

示例 #1 normalizer_normalize example

<?php
$char_A_ring = "\xC3\x85"; // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5)
$char_combining_ring_above = "\xCC\x8A";  // 'COMBINING RING ABOVE' (U+030A)
 
$char_1 = normalizer_normalize( $char_A_ring, Normalizer::FORM_C );
$char_2 = normalizer_normalize( 'A' . $char_combining_ring_above, Normalizer::FORM_C );
 
echo urlencode($char_1);
echo ' ';
echo urlencode($char_2);
?>

示例 #2 OO example

<?php
$char_A_ring = "\xC3\x85"; // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5)
$char_combining_ring_above = "\xCC\x8A";  // 'COMBINING RING ABOVE' (U+030A)
 
$char_1 = Normalizer::normalize( $char_A_ring, Normalizer::FORM_C );
$char_2 = Normalizer::normalize( 'A' . $char_combining_ring_above, Normalizer::FORM_C );
 
echo urlencode($char_1);
echo ' ';
echo urlencode($char_2);
?>

以上例程会输出:

%C3%85 %C3%85

参见

  • normalizer_is_normalized

简介

MessageFormatter is a concrete class that enables users to produce concatenated, language-neutral messages. The methods supplied in this class are used to build all the messages that are seen by end users.

The MessageFormatter class assembles messages from various fragments (such as text fragments, numbers, and dates) supplied by the program. Because of the MessageFormatter class, the program does not need to know the order of the fragments. The class uses the formatting specifications for the fragments to assemble them into a message that is contained in a single string within a resource bundle. For example, MessageFormatter enables you to print the phrase "Finished printing x out of y files..." in a manner that still allows for flexibility in translation.

Previously, an end user message was created as a sentence and handled as a string. This procedure created problems for localizers because the sentence structure, word order, number format and so on are very different from language to language. The language-neutral way to create messages keeps each part of the message separate and provides keys to the data. Using these keys, the MessageFormatter class can concatenate the parts of the message, localize them, and display a well-formed string to the end user.

MessageFormatter takes a set of objects, formats them, and then inserts the formatted strings into the pattern at the appropriate places. Choice formats can be used in conjunction with MessageFormatter to handle plurals, match numbers, and select from an array of items. Typically, the message format will come from resources and the arguments will be dynamically set at runtime.

类摘要

MessageFormatter

class MessageFormatter {

/* 方法 */

public __construct ( string $locale , string $pattern )

public static MessageFormatter create ( string $locale , string $pattern )

public static string formatMessage ( string $locale , string $pattern , array $args )

public string format ( array $args )

public int getErrorCode ( void )

public string getErrorMessage ( void )

public string getLocale ( void )

public string getPattern ( void )

public static array parseMessage ( string $locale , string $pattern , string $source )

public array parse ( string $value )

public bool setPattern ( string $pattern )

}

参见

MessageFormatter::create

MessageFormatter::__construct

msgfmt_create

Constructs a new Message Formatter

说明

面向对象风格 (method)

public static MessageFormatter MessageFormatter::create ( string $locale , string $pattern )

面向对象风格 (constructor):

public MessageFormatter::__construct ( string $locale , string $pattern )

过程化风格

MessageFormatter msgfmt_create ( string $locale , string $pattern )

Constructs a new Message Formatter

参数

locale
The locale to use when formatting arguments

pattern
The pattern string to stick arguments into. The pattern uses an 'apostrophe-friendly' syntax; it is run through » umsg_autoQuoteApostrophe before being interpreted.

返回值

The formatter object

错误/异常

When invoked as constructor, on failure an IntlException is thrown.

范例

示例 #1 msgfmt_create example

<?php
$fmt = msgfmt_create("en_US", "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree");
echo msgfmt_format($fmt, array(4560, 123, 4560/123));
$fmt = msgfmt_create("de", "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum");
echo msgfmt_format($fmt, array(4560, 123, 4560/123));
?>

示例 #2 OO example

<?php
$fmt = new MessageFormatter("en_US", "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree");
echo $fmt->format(array(4560, 123, 4560/123));
$fmt = new MessageFormatter("de", "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum");
echo $fmt->format(array(4560, 123, 4560/123));
?>

以上例程会输出:

4,560 monkeys on 123 trees make 37.073 monkeys per tree
4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum

参见

  • msgfmt_format
  • msgfmt_parse
  • msgfmt_get_error_code
  • msgfmt_get_error_message

MessageFormatter::formatMessage

msgfmt_format_message

Quick format message

说明

面向对象风格

public static string MessageFormatter::formatMessage ( string $locale , string $pattern , array $args )

过程化风格

string msgfmt_format_message ( string $locale , string $pattern , array $args )

Quick formatting function that formats the string without having to explicitly create the formatter object. Use this function when the format operation is done only once and does not need and parameters or state to be kept.

参数

locale
The locale to use for formatting locale-dependent parts

pattern
The pattern string to insert things into. The pattern uses an 'apostrophe-friendly' syntax; it is run through » umsg_autoQuoteApostrophe before being interpreted.

args
The array of values to insert into the format string

返回值

The formatted pattern string or FALSE if an error occurred

范例

示例 #1 msgfmt_format_message example

<?php
echo msgfmt_format_message("en_US", "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree\n", array(4560, 123, 4560/123));
echo msgfmt_format_message("de", "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum\n", array(4560, 123, 4560/123));
?>

示例 #2 OO example

<?php
echo MessageFormatter::formatMessage("en_US", "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree\n", array(4560, 123, 4560/123));
echo MessageFormatter::formatMessage("de", "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum\n", array(4560, 123, 4560/123));
?>

以上例程会输出:

4,560 monkeys on 123 trees make 37.073 monkeys per tree
4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum

参见

  • msgfmt_create
  • msgfmt_parse
  • msgfmt_get_error_code
  • msgfmt_get_error_message

MessageFormatter::format

msgfmt_format

Format the message

说明

面向对象风格

public string MessageFormatter::format ( array $args )

过程化风格

string msgfmt_format ( MessageFormatter $fmt , array $args )

Format the message by substituting the data into the format string according to the locale rules

参数

fmt
The message formatter

args
Arguments to insert into the format string

返回值

The formatted string, or FALSE if an error occurred

范例

示例 #1 msgfmt_format example

<?php
$fmt = msgfmt_create("en_US", "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree");
echo msgfmt_format($fmt, array(4560, 123, 4560/123));
$fmt = msgfmt_create("de", "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum");
echo msgfmt_format($fmt, array(4560, 123, 4560/123));
?>

示例 #2 OO example

<?php
$fmt = new MessageFormatter("en_US", "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree");
echo $fmt->format(array(4560, 123, 4560/123));
$fmt = new MessageFormatter("de", "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum");
echo $fmt->format(array(4560, 123, 4560/123));
?>

以上例程会输出:

4,560 monkeys on 123 trees make 37.073 monkeys per tree
4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum

参见

  • msgfmt_create
  • msgfmt_parse
  • msgfmt_format_message
  • msgfmt_get_error_code
  • msgfmt_get_error_message

MessageFormatter::getErrorCode

msgfmt_get_error_code

Get the error code from last operation

说明

面向对象风格

public int MessageFormatter::getErrorCode ( void )

过程化风格

int msgfmt_get_error_code ( MessageFormatter $fmt )

Get the error code from last operation.

参数

fmt
The message formatter

返回值

The error code, one of UErrorCode values. Initial value is U_ZERO_ERROR.

参见

  • msgfmt_get_error_message
  • intl_get_error_code
  • intl_is_failure

MessageFormatter::getErrorMessage

msgfmt_get_error_message

Get the error text from the last operation

说明

面向对象风格

public string MessageFormatter::getErrorMessage ( void )

过程化风格

string msgfmt_get_error_message ( MessageFormatter $fmt )

Get the error text from the last operation.

参数

fmt
The message formatter

返回值

Description of the last error.

范例

示例 #1 msgfmt_get_error_message example

<?php
$fmt = msgfmt_create("en_US", "{0, number} monkeys on {1, number} trees");
$str = msgfmt_format($fmt, array());
if(!$str) {
    echo "ERROR: ".msgfmt_get_error_message($fmt) . " (" . msgfmt_get_error_code($fmt) . ")\n";
}
?>

示例 #2 OO example

<?php
$fmt = new MessageFormatter("en_US", "{0, number} monkeys on {1, number} trees");
$str = $fmt->format(array());
if(!$str) {
    echo "ERROR: ".$fmt->getErrorMessage() . " (" . $fmt->getErrorCode() . ")\n";
}
?>

以上例程会输出:

ERROR: msgfmt_format: not enough parameters: U_ILLEGAL_ARGUMENT_ERROR (1)

参见

  • msgfmt_get_error_code
  • intl_get_error_code
  • intl_is_failure

MessageFormatter::getLocale

msgfmt_get_locale

Get the locale for which the formatter was created

说明

面向对象风格

public string MessageFormatter::getLocale ( void )

过程化风格

string msgfmt_get_locale ( NumberFormatter $formatter )

Get the locale for which the formatter was created.

参数

formatter
The formatter resource

返回值

The locale name

范例

示例 #1 msgfmt_get_locale example

<?php
$fmt = msgfmt_create('en_US', "Number {0,number}");
echo msgfmt_get_locale($fmt);
?>

示例 #2 OO example

<?php
$fmt = new MessageFormatter('en_US', "Number {0,number}");
echo $fmt->getLocale();
?>

以上例程会输出:

en_US

参见

  • msgfmt_create

MessageFormatter::getPattern

msgfmt_get_pattern

Get the pattern used by the formatter

说明

面向对象风格

public string MessageFormatter::getPattern ( void )

过程化风格

string msgfmt_get_pattern ( MessageFormatter $fmt )

Get the pattern used by the formatter

参数

fmt
The message formatter

返回值

The pattern string for this message formatter

范例

示例 #1 msgfmt_get_pattern example

<?php
$fmt = msgfmt_create( "en_US", "{0, number} monkeys on {1, number} trees" );
echo "Default pattern: '" . msgfmt_get_pattern( $fmt ) . "'\n";
echo "Formatting result: " . msgfmt_format( $fmt, array(123, 456) ) . "\n";

msgfmt_set_pattern( $fmt, "{0, number} trees hosting {1, number} monkeys" );
echo "New pattern: '" . msgfmt_get_pattern( $fmt ) . "'\n";
echo "Formatted number: " . msgfmt_format( $fmt, array(123, 456) ) . "\n";
?>

示例 #2 OO example

<?php
$fmt = new MessageFormatter( "en_US", "{0, number} monkeys on {1, number} trees" );
echo "Default pattern: '" . $fmt->getPattern() . "'\n";
echo "Formatting result: " . $fmt->format(array(123, 456)) . "\n";

$fmt->setPattern("{0, number} trees hosting {1, number} monkeys" );
echo "New pattern: '" . $fmt->getPattern() . "'\n";
echo "Formatted number: " . $fmt->format(array(123, 456)) . "\n";
?>

以上例程会输出:

Default pattern: '{0,number} monkeys on {1,number} trees'
Formatting result: 123 monkeys on 456 trees
New pattern: '{0,number} trees hosting {1,number} monkeys'
Formatted number: 123 trees hosting 456 monkeys

参见

  • msgfmt_create
  • msgfmt_set_pattern

MessageFormatter::parseMessage

msgfmt_parse_message

Quick parse input string

说明

面向对象风格

public static array MessageFormatter::parseMessage ( string $locale , string $pattern , string $source )

过程化风格

array msgfmt_parse_message ( string $locale , string $pattern , string $value )

Parses input string without explicitly creating the formatter object. Use this function when the format operation is done only once and does not need and parameters or state to be kept.

参数

locale
The locale to use for parsing locale-dependent parts

pattern
The pattern with which to parse the value.

source
The string to parse, conforming to the pattern.

返回值

An array containing items extracted, or FALSE on error

范例

示例 #1 msgfmt_parse_message example

<?php
$fmt = msgfmt_parse_message('en_US', "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree",
                            "4,560 monkeys on 123 trees make 37.073 monkeys per tree");
var_export($fmt);

$fmt = msgfmt_parse_message('de', "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum", 
                            "4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum");
var_export($fmt);
?>

示例 #2 OO example

<?php
$fmt = MessageFormatter::parseMessage('en_US', "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree",
                            "4,560 monkeys on 123 trees make 37.073 monkeys per tree");
var_export($fmt);

$fmt = MessageFormatter::parseMessage('de', "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum", 
                            "4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum");
var_export($fmt);
?>

以上例程会输出:

array (
  0 => 4560,
  1 => 123,
  2 => 37.073,
)
array (
  0 => 4560,
  1 => 123,
  2 => 37.073,
)

参见

  • msgfmt_create
  • msgfmt_format_message
  • msgfmt_parse

MessageFormatter::parse

msgfmt_parse

Parse input string according to pattern

说明

面向对象风格

public array MessageFormatter::parse ( string $value )

过程化风格

array msgfmt_parse ( MessageFormatter $fmt , string $value )

Parses input string and return any extracted items as an array.

参数

fmt
The message formatter

value
The string to parse

返回值

An array containing the items extracted, or FALSE on error

范例

示例 #1 msgfmt_parse example

<?php
$fmt = msgfmt_create('en_US', "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree");
$res = msgfmt_parse($fmt, "4,560 monkeys on 123 trees make 37.073 monkeys per tree");
var_export($res);

$fmt = msgfmt_create('de', "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum");
$res = msgfmt_parse($fmt, "4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum");
var_export($res);
?>

示例 #2 OO example

<?php
$fmt = new MessageFormatter('en_US', "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree");
$res = $fmt->parse("4,560 monkeys on 123 trees make 37.073 monkeys per tree");
var_export($res);

$fmt = new MessageFormatter('de', "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum");
$res = $fmt->parse("4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum");
var_export($res);
?>

以上例程会输出:

array (
  0 => 4560,
  1 => 123,
  2 => 37.073,
)
array (
  0 => 4560,
  1 => 123,
  2 => 37.073,
)

参见

  • msgfmt_create
  • msgfmt_format
  • msgfmt_parse_message

MessageFormatter::setPattern

msgfmt_set_pattern

Set the pattern used by the formatter

说明

面向对象风格

public bool MessageFormatter::setPattern ( string $pattern )

过程化风格

bool msgfmt_set_pattern ( MessageFormatter $fmt , string $pattern )

Set the pattern used by the formatter

参数

fmt
The message formatter

pattern
The pattern string to use in this message formatter. The pattern uses an 'apostrophe-friendly' syntax; it is run through » umsg_autoQuoteApostrophe before being interpreted.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 msgfmt_set_pattern example

<?php
$fmt = msgfmt_create( "en_US", "{0, number} monkeys on {1, number} trees" );
echo "Default pattern: '" . msgfmt_get_pattern( $fmt ) . "'\n";
echo "Formatting result: " . msgfmt_format( $fmt, array(123, 456) ) . "\n";

msgfmt_set_pattern( $fmt, "{0, number} trees hosting {1, number} monkeys" );
echo "New pattern: '" . msgfmt_get_pattern( $fmt ) . "'\n";
echo "Formatted number: " . msgfmt_format( $fmt, array(123, 456) ) . "\n";
?>

示例 #2 OO example

<?php
$fmt = new MessageFormatter( "en_US", "{0, number} monkeys on {1, number} trees" );
echo "Default pattern: '" . $fmt->getPattern() . "'\n";
echo "Formatting result: " . $fmt->format(array(123, 456)) . "\n";

$fmt->setPattern("{0, number} trees hosting {1, number} monkeys" );
echo "New pattern: '" . $fmt->getPattern() . "'\n";
echo "Formatted number: " . $fmt->format(array(123, 456)) . "\n";
?>

以上例程会输出:

Default pattern: '{0,number} monkeys on {1,number} trees'
Formatting result: 123 monkeys on 456 trees
New pattern: '{0,number} trees hosting {1,number} monkeys'
Formatted number: 123 trees hosting 456 monkeys

参见

  • msgfmt_create
  • msgfmt_get_pattern

简介

类摘要

IntlCalendar

class IntlCalendar {

/* 常量 */

const integer IntlCalendar::FIELD_ERA = 0 ;

const integer IntlCalendar::FIELD_YEAR = 1 ;

const integer IntlCalendar::FIELD_MONTH = 2 ;

const integer IntlCalendar::FIELD_WEEK_OF_YEAR = 3 ;

const integer IntlCalendar::FIELD_WEEK_OF_MONTH = 4 ;

const integer IntlCalendar::FIELD_DATE = 5 ;

const integer IntlCalendar::FIELD_DAY_OF_YEAR = 6 ;

const integer IntlCalendar::FIELD_DAY_OF_WEEK = 7 ;

const integer IntlCalendar::FIELD_DAY_OF_WEEK_IN_MONTH = 8 ;

const integer IntlCalendar::FIELD_AM_PM = 9 ;

const integer IntlCalendar::FIELD_HOUR = 10 ;

const integer IntlCalendar::FIELD_HOUR_OF_DAY = 11 ;

const integer IntlCalendar::FIELD_MINUTE = 12 ;

const integer IntlCalendar::FIELD_SECOND = 13 ;

const integer IntlCalendar::FIELD_MILLISECOND = 14 ;

const integer IntlCalendar::FIELD_ZONE_OFFSET = 15 ;

const integer IntlCalendar::FIELD_DST_OFFSET = 16 ;

const integer IntlCalendar::FIELD_YEAR_WOY = 17 ;

const integer IntlCalendar::FIELD_DOW_LOCAL = 18 ;

const integer IntlCalendar::FIELD_EXTENDED_YEAR = 19 ;

const integer IntlCalendar::FIELD_JULIAN_DAY = 20 ;

const integer IntlCalendar::FIELD_MILLISECONDS_IN_DAY = 21 ;

const integer IntlCalendar::FIELD_IS_LEAP_MONTH = 22 ;

const integer IntlCalendar::FIELD_FIELD_COUNT = 23 ;

const integer IntlCalendar::FIELD_DAY_OF_MONTH = 5 ;

const integer IntlCalendar::DOW_SUNDAY = 1 ;

const integer IntlCalendar::DOW_MONDAY = 2 ;

const integer IntlCalendar::DOW_TUESDAY = 3 ;

const integer IntlCalendar::DOW_WEDNESDAY = 4 ;

const integer IntlCalendar::DOW_THURSDAY = 5 ;

const integer IntlCalendar::DOW_FRIDAY = 6 ;

const integer IntlCalendar::DOW_SATURDAY = 7 ;

const integer IntlCalendar::DOW_TYPE_WEEKDAY = 0 ;

const integer IntlCalendar::DOW_TYPE_WEEKEND = 1 ;

const integer IntlCalendar::DOW_TYPE_WEEKEND_OFFSET = 2 ;

const integer IntlCalendar::DOW_TYPE_WEEKEND_CEASE = 3 ;

const integer IntlCalendar::WALLTIME_FIRST = 1 ;

const integer IntlCalendar::WALLTIME_LAST = 0 ;

const integer IntlCalendar::WALLTIME_NEXT_VALID = 2 ;

/* 方法 */

public bool add ( int $field , int $amount )

bool intlcal_add ( IntlCalendar $cal , int $field , int $amount )

public bool after ( IntlCalendar $other )

bool intlcal_after ( IntlCalendar $cal , IntlCalendar $other )

public bool before ( IntlCalendar $other )

bool intlcal_before ( IntlCalendar $cal , IntlCalendar $other )

public bool clear ([ int $field = NULL ] )

bool intlcal_clear ( IntlCalendar $cal [, int $field = NULL ] )

private __construct ( void )

public static IntlCalendar createInstance ([ mixed $timeZone = NULL [, string $locale = "" ]] )

IntlCalendar intlcal_create_instance ([ mixed $timeZone = NULL [, string $locale = "" ]] )

public bool equals ( IntlCalendar $other )

bool intlcal_equals ( IntlCalendar $cal , IntlCalendar $other )

public int fieldDifference ( float $when , int $field )

int intlcal_field_difference ( IntlCalendar $cal , float $when , int $field )

public static IntlCalendar fromDateTime ( mixed $dateTime )

IntlCalendar intlcal_from_date_time ( mixed $dateTime )

public int get ( int $field )

int intlcal_get ( IntlCalendar $cal , int $field )

public int getActualMaximum ( int $field )

int intlcal_get_actual_maximum ( IntlCalendar $cal , int $field )

public int getActualMinimum ( int $field )

int intlcal_get_actual_minimum ( IntlCalendar $cal , int $field )

public static array getAvailableLocales ( void )

array intlcal_get_available_locales ( void )

public int getDayOfWeekType ( int $dayOfWeek )

int intlcal_get_day_of_week_type ( IntlCalendar $cal , int $dayOfWeek )

public int getErrorCode ( void )

public string getErrorMessage ( void )

public int getFirstDayOfWeek ( void )

int intlcal_get_first_day_of_week ( IntlCalendar $cal )

public int getGreatestMinimum ( int $field )

int intlcal_get_greatest_minimum ( IntlCalendar $cal , int $field )

public static Iterator getKeywordValuesForLocale ( string $key , string $locale , bool $commonlyUsed )

Iterator intlcal_get_keyword_values_for_locale ( string $key , string $locale , bool $commonlyUsed )

public int getLeastMaximum ( int $field )

int intlcal_get_least_maximum ( IntlCalendar $cal , int $field )

public string getLocale ( int $localeType )

string intlcal_get_locale ( IntlCalendar $cal , int $localeType )

public int getMaximum ( int $field )

int intlcal_get_maximum ( IntlCalendar $cal , int $field )

public int getMinimalDaysInFirstWeek ( void )

int intlcal_get_minimal_days_in_first_week ( IntlCalendar $cal )

public int getMinimum ( int $field )

int intlcal_get_minimum ( IntlCalendar $cal , int $field )

public static float getNow ( void )

float intlcal_get_now ( void )

public int getRepeatedWallTimeOption ( void )

int intlcal_get_repeated_wall_time_option ( IntlCalendar $cal )

public int getSkippedWallTimeOption ( void )

int intlcal_get_skipped_wall_time_option ( IntlCalendar $cal )

public float getTime ( void )

float intlcal_get_time ( IntlCalendar $cal )

public IntlTimeZone getTimeZone ( void )

IntlTimeZone intlcal_get_time_zone ( IntlCalendar $cal )

public string getType ( void )

string intlcal_get_type ( IntlCalendar $cal )

public int getWeekendTransition ( string $dayOfWeek )

int intlcal_get_weekend_transition ( IntlCalendar $cal , string $dayOfWeek )

public bool inDaylightTime ( void )

bool intlcal_in_daylight_time ( IntlCalendar $cal )

public bool isEquivalentTo ( IntlCalendar $other )

bool intlcal_is_equivalent_to ( IntlCalendar $cal , IntlCalendar $other )

public bool isLenient ( void )

bool intlcal_is_lenient ( IntlCalendar $cal )

public bool isSet ( int $field )

bool intlcal_is_set ( IntlCalendar $cal , int $field )

public bool isWeekend ([ float $date = NULL ] )

bool intlcal_is_weekend ( IntlCalendar $cal [, float $date = NULL ] )

public bool roll ( int $field , mixed $amountOrUpOrDown )

bool intlcal_roll ( IntlCalendar $cal , int $field , mixed $amountOrUpOrDown )

public bool set ( int $field , int $value )

public bool set ( int $year , int $month [, int $dayOfMonth = NULL [, int $hour = NULL [, int $minute = NULL [, int $second = NULL ]]]] )

bool intlcal_set ( IntlCalendar $cal , int $field , int $value )

bool intlcal_set ( IntlCalendar $cal , int $year , int $month [, int $dayOfMonth = NULL [, int $hour = NULL [, int $minute = NULL [, int $second = NULL ]]]] )

public bool setFirstDayOfWeek ( int $dayOfWeek )

bool intlcal_set_first_day_of_week ( IntlCalendar $cal , int $dayOfWeek )

public bool setLenient ( bool $isLenient )

bool intlcal_set_lenient ( IntlCalendar $cal , bool $isLenient )

public bool setMinimalDaysInFirstWeek ( int $minimalDays )

bool intlcal_get_minimal_days_in_first_week ( IntlCalendar $cal , int $minimalDays )

public bool setRepeatedWallTimeOption ( int $wallTimeOption )

bool intlcal_set_repeated_wall_time_option ( IntlCalendar $cal , int $wallTimeOption )

public bool setSkippedWallTimeOption ( int $wallTimeOption )

bool intlcal_set_skipped_wall_time_option ( IntlCalendar $cal , int $wallTimeOption )

public bool setTime ( float $date )

bool intlcal_set_time ( IntlCalendar $cal , float $date )

public bool setTimeZone ( mixed $timeZone )

bool intlcal_set_time_zone ( IntlCalendar $cal , mixed $timeZone )

public DateTime toDateTime ( void )

DateTime intlcal_to_date_time ( IntlCalendar $cal )

}

预定义常量

IntlCalendar::FIELD_ERA
Calendar field numerically representing an era, for instance 1 for AD and 0 for BC in the Gregorian/Julian calendars and 235 for the Heisei (平成) era in the Japanese calendar. Not all calendars have more than one era.

IntlCalendar::FIELD_YEAR
Calendar field for the year. This is not unique across eras. If the calendar type has more than one era, generally the minimum value for this field will be 1.

IntlCalendar::FIELD_MONTH
Calendar field for the month. The month sequence is zero-based, so January (here used to signify the first month of the calendar; this may be called another name, such as Muharram in the Islamic calendar) is represented by 0, February by 1, …, December by 11 and, for calendars that have it, the 13th or leap month by 12.

IntlCalendar::FIELD_WEEK_OF_YEAR
Calendar field for the number of the week of the year. This depends on which day of the week is deemed to start the week and the minimal number of days in a week.

IntlCalendar::FIELD_WEEK_OF_MONTH
Calendar field for the number of the week of the month. This depends on which day of the week is deemed to start the week and the minimal number of days in a week.

IntlCalendar::FIELD_DATE
Calendar field for the day of the month. The same as IntlCalendar::FIELD_DAY_OF_MONTH, which has a clearer name.

IntlCalendar::FIELD_DAY_OF_YEAR
Calendar field for the day of the year. For the Gregorian calendar, starts with 1 and ends with 365 or 366.

IntlCalendar::FIELD_DAY_OF_WEEK
Calendar field for the day of the week. Its values start with 1 (Sunday, see IntlCalendar::DOW_SUNDAY and subsequent constants) and the last valid value is 7 (Saturday).

IntlCalendar::FIELD_DAY_OF_WEEK_IN_MONTH
Given a day of the week (Sunday, Monday, …), this calendar field assigns an ordinal to such a day of the week in a specific month. Thus, if the value of this field is 1 and the value of the day of the week is 2 (Monday), then the set day of the month is the 1st Monday of the month; the maximum value is 5.

Additionally, the value 0 and negative values are also allowed. The value 0 encompasses the seven days that occur immediately before the first seven days of a month (which therefore have a ‘day of week in month’ with value 1). Negative values starts counting from the end of the month – -1 points to the last occurrence of a day of the week in a month, -2 to the second last, and so on.

Unlike IntlCalendar::FIELD_WEEK_OF_MONTH and IntlCalendar::FIELD_WEEK_OF_YEAR, this value does not depend on IntlCalendar::getFirstDayOfWeek or on IntlCalendar::getMinimalDaysInFirstWeek. The first Monday is the first Monday, even if it occurs in a week that belongs to the previous month.

IntlCalendar::FIELD_AM_PM
Calendar field indicating whether a time is before noon (value 0, AM) or after (1). Midnight is AM, noon is PM.

IntlCalendar::FIELD_HOUR
Calendar field for the hour, without specifying whether itʼs in the morning or in the afternoon. Valid values are 0 to 11.

IntlCalendar::FIELD_HOUR_OF_DAY
Calendar field for the full (24h) hour of the day. Valid values are 0 to 23.

IntlCalendar::FIELD_MINUTE
Calendar field for the minutes component of the time.

IntlCalendar::FIELD_SECOND
Calendar field for the seconds component of the time.

IntlCalendar::FIELD_MILLISECOND
Calendar field the milliseconds component of the time.

IntlCalendar::FIELD_ZONE_OFFSET
Calendar field indicating the raw offset of the timezone, in milliseconds. The raw offset is the timezone offset, excluding any offset due to daylight saving time.

IntlCalendar::FIELD_DST_OFFSET
Calendar field for the daylight saving time offset of the calendarʼs timezone, in milliseconds, if active for calendarʼs time.

IntlCalendar::FIELD_YEAR_WOY
Calendar field representing the year for week of year purposes.

IntlCalendar::FIELD_DOW_LOCAL
Calendar field for the localized day of the week. This is a value between 1 and 7, 1 being used for the day of the week that matches the value returned by IntlCalendar::getFirstDayOfWeek.

IntlCalendar::FIELD_EXTENDED_YEAR
Calendar field for a year number representation that is continuous across eras. For the Gregorian calendar, the value of this field matches that of IntlCalendar::FIELD_YEAR for AD years; a BC year y is represented by -y + 1.

IntlCalendar::FIELD_JULIAN_DAY
Calendar field for a modified Julian day number. It is different from a conventional Julian day number in that its transitions occur at local zone midnight rather than at noon UTC. It uniquely identifies a date.

IntlCalendar::FIELD_MILLISECONDS_IN_DAY
Calendar field encompassing the information in IntlCalendar::FIELD_HOUR_OF_DAY, IntlCalendar::FIELD_MINUTE, IntlCalendar::FIELD_SECOND and IntlCalendar::FIELD_MILLISECOND. Range is from the 0 to 24 * 3600 * 1000 - 1. It is not the amount of milliseconds elapsed in the day since on DST transitions it will have discontinuities analog to those of the wall time.

IntlCalendar::FIELD_IS_LEAP_MONTH
Calendar field whose value is 1 for indicating a leap month and 0 otherwise.

IntlCalendar::FIELD_FIELD_COUNT
The total number of fields.

IntlCalendar::FIELD_DAY_OF_MONTH
Alias for IntlCalendar::FIELD_DATE.

IntlCalendar::DOW_SUNDAY
Sunday.

IntlCalendar::DOW_MONDAY
Monday.

IntlCalendar::DOW_TUESDAY
Tuesday.

IntlCalendar::DOW_WEDNESDAY
Wednesday.

IntlCalendar::DOW_THURSDAY
Thursday.

IntlCalendar::DOW_FRIDAY
Friday.

IntlCalendar::DOW_SATURDAY
Saturday.

IntlCalendar::DOW_TYPE_WEEKDAY
Output of IntlCalendar::getDayOfWeekType indicating a day of week is a weekday.

IntlCalendar::DOW_TYPE_WEEKEND
Output of IntlCalendar::getDayOfWeekType indicating a day of week belongs to the weekend.

IntlCalendar::DOW_TYPE_WEEKEND_OFFSET
Output of IntlCalendar::getDayOfWeekType indicating the weekend begins during the given day of week.

IntlCalendar::DOW_TYPE_WEEKEND_CEASE
Output of IntlCalendar::getDayOfWeekType indicating the weekend ends during the given day of week.

IntlCalendar::WALLTIME_FIRST
Output of IntlCalendar::getSkippedWallTimeOption indicating that wall times in the skipped range should refer to the same instant as wall times with one hour less and of IntlCalendar::getRepeatedWallTimeOption indicating the wall times in the repeated range should refer to the instant of the first occurrence of such wall time.

IntlCalendar::WALLTIME_LAST
Output of IntlCalendar::getSkippedWallTimeOption indicating that wall times in the skipped range should refer to the same instant as wall times with one hour after and of IntlCalendar::getRepeatedWallTimeOption indicating the wall times in the repeated range should refer to the instant of the second occurrence of such wall time.

IntlCalendar::WALLTIME_NEXT_VALID
Output of IntlCalendar::getSkippedWallTimeOption indicating that wall times in the skipped range should refer to the instant when the daylight saving time transition occurs (begins).

IntlCalendar::add

Add a (signed) amount of time to a field

说明

面向对象风格

public bool IntlCalendar::add ( int $field , int $amount )

过程化风格

bool intlcal_add ( IntlCalendar $cal , int $field , int $amount )

Add a signed amount to a field. Adding a positive amount allows advances in time, even if the numeric value of the field decreases (e.g. when working with years in BC dates).

Other fields may need to adjusted – for instance, adding a month to the 31st of January will result in the 28th (or 29th) of February. Contrary to IntlCalendar::roll, when a value wraps around, more significant fields may change. For instance, adding a day to the 31st of January will result in the 1st of February, not the 1st of January.

参数

cal
The IntlCalendar resource.

field
One of the IntlCalendar date/time field constants. These are integer values between 0 and IntlCalendar::FIELD_COUNT.

amount
The signed amount to add to the current field. If the amount is positive, the instant will be moved forward; if it is negative, the instant will be moved into the past. The unit is implicit to the field type. For instance, hours for IntlCalendar::FIELD_HOUR_OF_DAY.

返回值

Returns TRUE on success 或者在失败时返回 FALSE.

范例

示例 #1 IntlCalendar::add

<?php
ini_set('intl.default_locale', 'fr_FR');
ini_set('date.timezone', 'UTC');

$cal = new IntlGregorianCalendar(2012, 0 /* January */, 31);
echo IntlDateFormatter::formatObject($cal), "\n";

$cal->add(IntlCalendar::FIELD_MONTH, 1);
echo IntlDateFormatter::formatObject($cal), "\n";

$cal->add(IntlCalendar::FIELD_DAY_OF_MONTH, 1);
echo IntlDateFormatter::formatObject($cal), "\n";

以上例程会输出:

31 janv. 2012 00:00:00
29 févr. 2012 00:00:00
1 mars 2012 00:00:00

IntlCalendar::after

Whether this objectʼs time is after that of the passed object

说明

面向对象风格

public bool IntlCalendar::after ( IntlCalendar $other )

过程化风格

bool intlcal_after ( IntlCalendar $cal , IntlCalendar $other )

Returns whether this objectʼs time succeeds the argumentʼs time.

参数

cal
The IntlCalendar resource.

other
The calendar whose time will be checked against the primary objectʼs time.

返回值

Returns TRUE if this objectʼs current time is after that of the calendar argumentʼs time. Returns FALSE otherwise. Also returns FALSE on failure. You can use exceptions or intl_get_error_code to detect error conditions.

范例

示例 #1 IntlCalendar::after

<?php
$cal1 = IntlCalendar::createInstance();
$cal2 = clone $cal1;

var_dump($cal1->after($cal2), //false
        $cal2->after($cal1)); //false

$cal1->roll(IntlCalendar::FIELD_MILLISECOND, true);

var_dump($cal1->after($cal2), //true
        $cal2->after($cal1)); //false

IntlCalendar::before

Whether this objectʼs time is before that of the passed object

说明

面向对象风格

public bool IntlCalendar::before ( IntlCalendar $other )

过程化风格

bool intlcal_before ( IntlCalendar $cal , IntlCalendar $other )

Returns whether this objectʼs time precedes the argumentʼs time.

参数

cal
The IntlCalendar resource.

other
The calendar whose time will be checked against the primary objectʼs time.

返回值

Returns TRUE if this objectʼs current time is before that of the calendar argumentʼs time. Returns FALSE otherwise. Also returns FALSE on failure. You can use exceptions or intl_get_error_code to detect error conditions.

IntlCalendar::clear

Clear a field or all fields

说明

面向对象风格

public bool IntlCalendar::clear ([ int $field = NULL ] )

过程化风格

bool intlcal_clear ( IntlCalendar $cal [, int $field = NULL ] )

Clears either all of the fields or a specific field. A cleared field is marked as unset, giving it the lowest priority against overlapping fields or even default values when calculating the time. Additionally, its value is set to 0, though given the fieldʼs low priority, its value may have been internally set to another value by the time the field has finished been queried.

参数

cal
The IntlCalendar resource.

field
One of the IntlCalendar date/time field constants. These are integer values between 0 and IntlCalendar::FIELD_COUNT.

返回值

Returns TRUE on success 或者在失败时返回 FALSE. Failure can only occur is invalid arguments are provided.

范例

示例 #1 IntlCalendar::clear examples

<?php
ini_set('intl.default_locale', 'es_ES');
ini_set('date.timezone', 'UTC');

$fields = array(
    'FIELD_ERA'                  => 0,
    'FIELD_YEAR'                 => 1,
    'FIELD_MONTH'                => 2,
    'FIELD_WEEK_OF_YEAR'         => 3,
    'FIELD_WEEK_OF_MONTH'        => 4,
    'FIELD_DATE'                 => 5,
    'FIELD_DAY_OF_YEAR'          => 6,
    'FIELD_DAY_OF_WEEK'          => 7,
    'FIELD_DAY_OF_WEEK_IN_MONTH' => 8,
    'FIELD_AM_PM'                => 9,
    'FIELD_HOUR'                 => 10,
    'FIELD_HOUR_OF_DAY'          => 11,
    'FIELD_MINUTE'               => 12,
    'FIELD_SECOND'               => 13,
    'FIELD_MILLISECOND'          => 14,
    'FIELD_ZONE_OFFSET'          => 15,
    'FIELD_DST_OFFSET'           => 16,
    'FIELD_YEAR_WOY'             => 17,
    'FIELD_DOW_LOCAL'            => 18,
    'FIELD_EXTENDED_YEAR'        => 19,
    'FIELD_JULIAN_DAY'           => 20,
    'FIELD_MILLISECONDS_IN_DAY'  => 21,
    'FIELD_IS_LEAP_MONTH'        => 22,
    'FIELD_FIELD_COUNT'          => 23,
);
function getSetFields(IntlCalendar $cal) {
    global $fields;
    $ret = array();
    foreach ($fields as $name => $value) {
        if ($cal->isSet($value)) {
            $ret[] = $name;
        }
    }
    return $ret;
}

$cal = new IntlGregorianCalendar(2013, 2 /* March */, 15);
echo "After GregorianCalendar creation\n";
print_r(getSetFields($cal));
echo "\n";

echo IntlDateFormatter::formatObject($cal), "\n";
echo "After the formatter requested the extended year\n";
print_r(getSetFields($cal));
echo "\n";

$cal->clear(IntlCalendar::FIELD_YEAR);
echo "After the year has been cleared, the date stays the same\n";
echo IntlDateFormatter::formatObject($cal), "\n";
echo "because FIELD_EXTENDED_YEAR is still set\n";
print_r(getSetFields($cal));
echo "\n";

var_dump($cal->clear(IntlCalendar::FIELD_EXTENDED_YEAR));
echo "After the extended year has been cleared\n";
print_r(getSetFields($cal));
echo IntlDateFormatter::formatObject($cal), "\n";
echo "\n";

echo "After the fields are recalculated,\n"
        . " extended year is set again (to 1970)\n";
print_r(getSetFields($cal));
echo "\n";

$cal->clear();
echo "After calling variant with no arguments\n";
print_r(getSetFields($cal));
echo IntlDateFormatter::formatObject($cal), "\n";

以上例程会输出:

After GregorianCalendar creation
Array
(
    [0] => FIELD_ERA
    [1] => FIELD_YEAR
    [2] => FIELD_MONTH
    [3] => FIELD_DATE
)

15/03/2013 00:00:00
After the formatter requested the extended year
Array
(
    [0] => FIELD_ERA
    [1] => FIELD_YEAR
    [2] => FIELD_MONTH
    [3] => FIELD_DATE
    [4] => FIELD_EXTENDED_YEAR
)

After the year has been cleared, the date stays the same
15/03/2013 00:00:00
because FIELD_EXTENDED_YEAR is still set
Array
(
    [0] => FIELD_ERA
    [1] => FIELD_MONTH
    [2] => FIELD_DATE
    [3] => FIELD_EXTENDED_YEAR
)

bool(true)
After the extended year has been cleared
Array
(
    [0] => FIELD_ERA
    [1] => FIELD_MONTH
    [2] => FIELD_DATE
)
15/03/1970 00:00:00

After the fields are recalculated,
 extended year is set again (to 1970)
Array
(
    [0] => FIELD_ERA
    [1] => FIELD_MONTH
    [2] => FIELD_DATE
    [3] => FIELD_EXTENDED_YEAR
)

After calling variant with no arguments
Array
(
)
01/01/1970 00:00:00

IntlCalendar::__construct

Private constructor for disallowing instantiation

说明

private IntlCalendar::__construct ( void )

A private constructor for disallowing instantiation with the new operator.

Call IntlCalendar::createInstance instead.

参数

此函数没有参数。

返回值

没有返回值。

IntlCalendar::createInstance

Create a new IntlCalendar

说明

面向对象风格

public static IntlCalendar IntlCalendar::createInstance ([ mixed $timeZone = NULL [, string $locale = "" ]] )

过程化风格

IntlCalendar intlcal_create_instance ([ mixed $timeZone = NULL [, string $locale = "" ]] )

Given a timezone and locale, this method creates an IntlCalendar object. This factory method may return a subclass of IntlCalendar.

The calendar created will represent the time instance at which it was created, based on the system time. The fields can all be cleared by calling IntCalendar::clear with no arguments. See also IntlGregorianCalendar::__construct.

参数

timeZone
The timezone to use.

  • NULL, in which case the default timezone will be used, as specified in the ini setting date.timezone or through the function date_default_timezone_set and as returned by date_default_timezone_get.

  • An IntlTimeZone, which will be used directly.

  • A DateTimeZone. Its identifier will be extracted and an ICU timezone object will be created; the timezone will be backed by ICUʼs database, not PHPʼs.

  • A string, which should be a valid ICU timezone identifier. See IntlTimeZone::createTimeZoneIDEnumeration. Raw offsets such as "GMT+08:30" are also accepted.

locale
A locale to use or NULL to use the default locale.

返回值

The created IntlCalendar instance or NULL on failure.

范例

示例 #1 IntlCalendar::createInstance

<?php
ini_set('intl.default_locale', 'es_ES');
ini_set('date.timezone', 'Europe/Madrid');

$cal = IntlCalendar::createInstance();
echo "No arguments\n";
var_dump(get_class($cal),
        IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL));
echo "\n";

echo "Explicit timezone\n";
$cal = IntlCalendar::createInstance(IntlTimeZone::getGMT());
var_dump(get_class($cal),
        IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL));
echo "\n";

echo "Explicit locale (with calendar)\n";
$cal = IntlCalendar::createInstance(NULL, 'es_ES@calendar=persian');
var_dump(get_class($cal),
        IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL));

以上例程会输出:

No arguments
string(21) "IntlGregorianCalendar"
string(68) "martes 18 de junio de 2013 14:11:02 Hora de verano de Europa Central"

Explicit timezone
string(21) "IntlGregorianCalendar"
string(45) "martes 18 de junio de 2013 12:11:02 GMT+00:00"

Explicit locale (with calendar)
string(12) "IntlCalendar"
string(70) "martes 28 de Khordad de 1392 14:11:02 Hora de verano de Europa Central"

参见

  • IntlGregorianCalendar::__construct

IntlCalendar::equals

Compare time of two IntlCalendar objects for equality

说明

面向对象风格

public bool IntlCalendar::equals ( IntlCalendar $other )

过程化风格

bool intlcal_equals ( IntlCalendar $cal , IntlCalendar $other )

Returns true if this calendar and the given calendar have the same time. The settings, calendar types and field states do not have to be the same.

参数

cal
The IntlCalendar resource.

other
The calendar to compare with the primary object.

返回值

Returns TRUE if the current time of both this and the passed in IntlCalendar object are the same, or FALSE otherwise. The value FALSE can also be returned on failure. This can only happen if bad arguments are passed in. In any case, the two cases can be distinguished by calling intl_get_error_code.

范例

示例 #1 IntlCalendar::equals

<?php
ini_set('date.timezone', 'UTC');

$cal1 = IntlCalendar::createInstance(NULL, 'es_ES');
$cal2 = clone $cal1;

var_dump($cal1->equals($cal2)); //TRUE

//The locale is not included in the comparison
$cal2 = IntlCalendar::createInstance(NULL, 'pt_PT');
$cal2->setTime($cal1->getTime());
var_dump($cal1->equals($cal2)); //TRUE

//And set fields state is not included as well
$cal2->clear(IntlCalendar::FIELD_YEAR);
var_dump($cal1->isSet(IntlCalendar::FIELD_YEAR) ==
        $cal2->isSet(IntlCalendar::FIELD_YEAR)); //FALSE
var_dump($cal1->equals($cal2)); //TRUE

//Neither is the calendar type
$cal2 = IntlCalendar::createInstance(NULL, 'es_ES@calendar=islamic');
$cal2->setTime($cal1->getTime());
var_dump($cal1->equals($cal2)); //TRUE

//Only the time is
$cal2 = clone $cal1;
$cal2->setTime($cal1->getTime() + 1.);
var_dump($cal1->equals($cal2)); //FALSE

IntlCalendar::fieldDifference

Calculate difference between given time and this objectʼs time

说明

面向对象风格

public int IntlCalendar::fieldDifference ( float $when , int $field )

过程化风格

int intlcal_field_difference ( IntlCalendar $cal , float $when , int $field )

Return the difference between the given time and the time this object is set to, with respect to the quantity specified the field parameter.

This method is meant to be called successively, first with the most significant field of interest down to the least significant field. To this end, as a side effect, this calendarʼs value for the field specified is advanced by the amount returned.

参数

cal
The IntlCalendar resource.

when
The time against which to compare the quantity represented by the field. For the result to be positive, the time given for this parameter must be ahead of the time of the object the method is being invoked on.

field
The field that represents the quantity being compared.

One of the IntlCalendar date/time field constants. These are integer values between 0 and IntlCalendar::FIELD_COUNT.

返回值

Returns a (signed) difference of time in the unit associated with the specified field 或者在失败时返回 FALSE.

范例

示例 #1 IntlCalendar::fieldDifference

<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'fr_FR');

$cal1 = IntlCalendar::fromDateTime('2012-02-29 09:00:11');
$cal2 = IntlCalendar::fromDateTime('2013-03-01 09:19:29');
$time = $cal2->getTime();

echo "Time before: ", IntlDateFormatter::formatObject($cal1), "\n";

printf(
    "The difference in time is %d year(s), %d month(s), "
  . "%d day(s), %d hour(s) and %d minute(s)\n",
    $cal1->fieldDifference($time, IntlCalendar::FIELD_YEAR),
    $cal1->fieldDifference($time, IntlCalendar::FIELD_MONTH),
    $cal1->fieldDifference($time, IntlCalendar::FIELD_DAY_OF_MONTH),
    $cal1->fieldDifference($time, IntlCalendar::FIELD_HOUR_OF_DAY),
    $cal1->fieldDifference($time, IntlCalendar::FIELD_MINUTE)
);

//now it was advanced to the target time, exception for the seconds,
//for which we did not measure the difference
echo "Time after: ", IntlDateFormatter::formatObject($cal1), "\n";

以上例程会输出:

Time before: 29 févr. 2012 09:00:11
The difference in time is 1 year(s), 0 month(s), 1 day(s), 0 hour(s) and 19 minute(s)
Time after: 1 mars 2013 09:19:11

IntlCalendar::fromDateTime

Create an IntlCalendar from a DateTime object or string

说明

面向对象风格

public static IntlCalendar IntlCalendar::fromDateTime ( mixed $dateTime )

过程化风格

IntlCalendar intlcal_from_date_time ( mixed $dateTime )

Creates an IntlCalendar object either from a DateTime object or from a string from which a DateTime object can be built.

The new calendar will represent not only the same instant as the given DateTime (subject to precision loss for dates very far into the past or future), but also the same timezone (subject to the caveat that different timezone databases will be used, and therefore the results may differ).

参数

dateTime
A DateTime object or a string that can be passed to DateTime::__construct.

返回值

The created IntlCalendar object or NULL in case of failure. If a string is passed, any exception that occurs inside the DateTime constructor is propagated.

范例

示例 #1 IntlCalendar::fromDateTime

<?php
ini_set('date.timezone', 'Europe/Lisbon');

//same as IntlCalendar::fromDateTime(new DateTime(...))
$cal1 = IntlCalendar::fromDateTime('2013-02-28 00:01:02 Europe/Berlin');

//Note the timezone is Europe/Berlin, not the default Europe/Lisbon
echo IntlDateFormatter::formatObject($cal1, 'yyyy MMMM d HH:mm:ss VVVV', 'de_DE'), "\n";

以上例程会输出:

2013 Februar 28 00:01:02 Deutschland Zeit

IntlCalendar::get

Get the value for a field

说明

面向对象风格

public int IntlCalendar::get ( int $field )

过程化风格

int intlcal_get ( IntlCalendar $cal , int $field )

Gets the value for a specific field.

参数

cal
The IntlCalendar resource.

field
One of the IntlCalendar date/time field constants. These are integer values between 0 and IntlCalendar::FIELD_COUNT.

返回值

An integer with the value of the time field.

范例

示例 #1 IntlCalendar::get

<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'en_US');

$class = new ReflectionClass('IntlCalendar');
$fields = array();
foreach ($class->getConstants() as $name => $val) {
    if (strpos($name, 'FIELD_') !== 0 || $val > 22)
        continue;
    $fields[$val] = $name;
}

$cal = IntlCalendar::createInstance(); // current time
var_dump(IntlDateFormatter::formatObject($cal));
foreach ($fields as $val => $name) {
    echo "$val ($name)", "\n    ", $cal->get($val), "\n";
}

以上例程会输出:

string(23) "Jul 1, 2013, 4:44:44 AM"
0 (FIELD_ERA)
    1
1 (FIELD_YEAR)
    2013
2 (FIELD_MONTH)
    6
3 (FIELD_WEEK_OF_YEAR)
    27
4 (FIELD_WEEK_OF_MONTH)
    1
5 (FIELD_DAY_OF_MONTH)
    1
6 (FIELD_DAY_OF_YEAR)
    182
7 (FIELD_DAY_OF_WEEK)
    2
8 (FIELD_DAY_OF_WEEK_IN_MONTH)
    1
9 (FIELD_AM_PM)
    0
10 (FIELD_HOUR)
    4
11 (FIELD_HOUR_OF_DAY)
    4
12 (FIELD_MINUTE)
    44
13 (FIELD_SECOND)
    44
14 (FIELD_MILLISECOND)
    551
15 (FIELD_ZONE_OFFSET)
    0
16 (FIELD_DST_OFFSET)
    3600000
17 (FIELD_YEAR_WOY)
    2013
18 (FIELD_DOW_LOCAL)
    2
19 (FIELD_EXTENDED_YEAR)
    2013
20 (FIELD_JULIAN_DAY)
    2456475
21 (FIELD_MILLISECONDS_IN_DAY)
    17084551
22 (FIELD_IS_LEAP_MONTH)
    0

IntlCalendar::getActualMaximum

The maximum value for a field, considering the objectʼs current time

说明

面向对象风格

public int IntlCalendar::getActualMaximum ( int $field )

过程化风格

int intlcal_get_actual_maximum ( IntlCalendar $cal , int $field )

Returns a fieldʼs relative maximum value around the current time. The exact semantics vary by field, but in the general case this is the value that would be obtained if one would set the field value into the smallest relative maximum for the field and would increment it until reaching the global maximum or the field value wraps around, in which the value returned would be the global maximum or the value before the wrapping, respectively.

For instance, in the gregorian calendar, the actual maximum value for the day of month would vary between 28 and 31, depending on the month and year of the current time.

参数

cal
The IntlCalendar resource.

field
One of the IntlCalendar date/time field constants. These are integer values between 0 and IntlCalendar::FIELD_COUNT.

返回值

An int representing the maximum value in the units associated with the given field 或者在失败时返回 FALSE.

范例

示例 #1 IntlCalendar::getActualMaximum

<?php
ini_set('date.timezone', 'Europe/Lisbon');

$cal = IntlCalendar::fromDateTime('2013-02-15');
var_dump($cal->getActualMaximum(IntlCalendar::FIELD_DAY_OF_MONTH)); //28

$cal->add(IntlCalendar::FIELD_EXTENDED_YEAR, -1);
var_dump($cal->getActualMaximum(IntlCalendar::FIELD_DAY_OF_MONTH)); //29

以上例程会输出:

int(28)
int(29)

参见

  • IntlCalendar::getMaximum
  • IntlCalendar::getLeastMaximum
  • IntlCalendar::getActualMinimum

IntlCalendar::getActualMinimum

The minimum value for a field, considering the objectʼs current time

说明

面向对象风格

public int IntlCalendar::getActualMinimum ( int $field )

过程化风格

int intlcal_get_actual_minimum ( IntlCalendar $cal , int $field )

Returns a fieldʼs relative minimum value around the current time. The exact semantics vary by field, but in the general case this is the value that would be obtained if one would set the field value into the greatest relative minimum for the field and would decrement it until reaching the global minimum or the field value wraps around, in which the value returned would be the global minimum or the value before the wrapping, respectively.

For the Gregorian calendar, this is always the same as IntlCalendar::getMinimum.

参数

cal
The IntlCalendar resource.

field
One of the IntlCalendar date/time field constants. These are integer values between 0 and IntlCalendar::FIELD_COUNT.

返回值

An int representing the minimum value in the fieldʼs unit 或者在失败时返回 FALSE.

参见

  • IntlCalendar::getMinimum
  • IntlCalendar::getGreatestMinimum
  • IntlCalendar::getActualMaximum

IntlCalendar::getAvailableLocales

Get array of locales for which there is data

说明

面向对象风格

public static array IntlCalendar::getAvailableLocales ( void )

过程化风格

array intlcal_get_available_locales ( void )

Gives the list of locales for which calendars are installed. As of ICU 51, this is the list of all installed ICU locales.

参数

此函数没有参数。

返回值

An array of strings, one for which locale.

范例

示例 #1 IntlCalendar::getAvailableLocales

<?php
print_r(IntlCalendar::getAvailableLocales());

以上例程会输出:

Array
(
    [0] => af
    [1] => af_NA
    [2] => af_ZA
    [3] => agq
    [4] => agq_CM
    [5] => ak
    [6] => ak_GH
    [7] => am
    [8] => am_ET
    [9] => ar
    [10] => ar_001
    [11] => ar_AE
    [12] => ar_BH
    [13] => ar_DJ
    … output abbreviated …
    [595] => zh_Hant_HK
    [596] => zh_Hant_MO
    [597] => zh_Hant_TW
    [598] => zu
    [599] => zu_ZA
)

IntlCalendar::getDayOfWeekType

Tell whether a day is a weekday, weekend or a day that has a transition between the two

说明

面向对象风格

public int IntlCalendar::getDayOfWeekType ( int $dayOfWeek )

过程化风格

int intlcal_get_day_of_week_type ( IntlCalendar $cal , int $dayOfWeek )

Returns whether the passed day is a weekday (IntlCalendar::DOW_TYPE_WEEKDAY), a weekend day (IntlCalendar::DOW_TYPE_WEEKEND), a day during which a transition occurs into the weekend (IntlCalendar::DOW_TYPE_WEEKEND_OFFSET) or a day during which the weekend ceases (IntlCalendar::DOW_TYPE_WEEKEND_CEASE).

If the return is either IntlCalendar::DOW_TYPE_WEEKEND_OFFSET or IntlCalendar::DOW_TYPE_WEEKEND_CEASE, then IntlCalendar::getWeekendTransition can be called to obtain the time of the transition.

This function requires ICU 4.4 or later.

参数

cal
The IntlCalendar resource.

dayOfWeek
One of the constants IntlCalendar::DOW_SUNDAY, IntlCalendar::DOW_MONDAY, …, IntlCalendar::DOW_SATURDAY.

返回值

Returns one of the constants IntlCalendar::DOW_TYPE_WEEKDAY, IntlCalendar::DOW_TYPE_WEEKEND, IntlCalendar::DOW_TYPE_WEEKEND_OFFSET or IntlCalendar::DOW_TYPE_WEEKEND_CEASE 或者在失败时返回 FALSE.

范例

示例 #1 IntlCalendar::getDayOfWeekType

<?php

foreach (array('en_US', 'ar_SA') as $locale) {
    echo "Locale: ", Locale::getDisplayName($locale, "en_US"), "\n";

    $cal = IntlCalendar::createInstance('UTC', $locale);

    for ($i = IntlCalendar::DOW_SUNDAY; $i <= IntlCalendar::DOW_SATURDAY; $i++) {
        echo $i, " ", $cal->getDayOfWeekType($i), " ",
                $cal->getDayOfWeekType($i) >= IntlCalendar::DOW_TYPE_WEEKEND_OFFSET
                        ? $cal->getWeekendTransition($i)
                        : '',
                "\n";
    }
    echo "\n";
}

以上例程会输出:

Locale: English (United States)
1 3 86400000
2 0 
3 0 
4 0 
5 0 
6 0 
7 1 

Locale: Arabic (Saudi Arabia)
1 0 
2 0 
3 0 
4 0 
5 1 
6 3 86400000
7 0 

IntlCalendar::getErrorCode

intlcal_get_error_code

Get last error code on the object

说明

面向对象风格 (method):

public int IntlCalendar::getErrorCode ( void )

过程化风格:

int intlcal_get_error_code ( IntlCalendar $calendar )

Returns the numeric ICU error code for the last call on this object (including cloning) or the IntlCalendar given for the calendar parameter (in the procedural‒style version). This may indicate only a warning (negative error code) or no error at all (U_ZERO_ERROR). The actual presence of an error can be tested with intl_is_failure.

Invalid arguments detected on the PHP side (before invoking functions of the ICU library) are not recorded for the purposes of this function.

The last error that occurred in any call to a function of the intl extension, including early argument errors, can be obtained with intl_get_error_code. This function resets the global error code, but not the objectʼs error code.

参数

calendar
The calendar object, on the procedural style interface.

返回值

An ICU error code indicating either success, failure or a warning.

范例

示例 #1 IntlCalendar::getErrorCode and IntlCalendar::getErrorMessage

<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "nl");

$intlcal = new IntlGregorianCalendar(2012, 1, 29);
var_dump(
    $intlcal->getErrorCode(),
    $intlcal->getErrorMessage()
);
$intlcal->fieldDifference(-1e100, IntlCalendar::FIELD_SECOND);

var_dump(
    $intlcal->getErrorCode(),
    $intlcal->getErrorMessage()
);

以上例程会输出:

int(0)
string(12) "U_ZERO_ERROR"

Warning: IntlCalendar::fieldDifference(): intlcal_field_difference: Call to ICU method has failed in /home/glopes/php/ws/example.php on line 10
int(1)
string(81) "intlcal_field_difference: Call to ICU method has failed: U_ILLEGAL_ARGUMENT_ERROR"

参见

  • IntlCalendar::getErrorMessage
  • intl_is_failure
  • intl_error_name
  • intl_get_error_code
  • intl_get_error_message

IntlCalendar::getErrorMessage

intlcal_get_error_message

Get last error message on the object

说明

面向对象风格 (method):

public string IntlCalendar::getErrorMessage ( void )

过程化风格:

string intlcal_get_error_message ( IntlCalendar $calendar )

Returns the error message (if any) associated with the error reported by IntlCalendar::getErrorCode or intlcal_get_error_code. If there is no associated error message, only the string representation of the name of the error constant will be returned. Otherwise, the message also includes a message set on the side of the PHP binding.

参数

calendar
The calendar object, on the procedural style interface.

返回值

The error message associated with last error that occurred in a function call on this object, or a string indicating the non-existance of an error.

范例

示例 #1 IntlCalendar::getErrorMessage

<?php
$cal = IntlCalendar::createInstance('UTC', 'en_US');
var_dump($cal->getErrorMessage());

$cal->getWeekendTransition(IntlCalendar::DOW_WEDNESDAY);
var_dump($cal->getErrorMessage());

以上例程会输出:

string(12) "U_ZERO_ERROR"
string(82) "intlcal_get_weekend_transition: Error calling ICU method: U_ILLEGAL_ARGUMENT_ERROR"

IntlCalendar::getFirstDayOfWeek

Get the first day of the week for the calendarʼs locale

说明

面向对象风格

public int IntlCalendar::getFirstDayOfWeek ( void )

过程化风格

int intlcal_get_first_day_of_week ( IntlCalendar $cal )

The week day deemed to start a week, either the default value for this locale or the value set with IntlCalendar::setFirstDayOfWeek.

参数

cal
The IntlCalendar resource.

返回值

One of the constants IntlCalendar::DOW_SUNDAY, IntlCalendar::DOW_MONDAY, …, IntlCalendar::DOW_SATURDAY 或者在失败时返回 FALSE.

范例

示例 #1 IntlCalendar::getFirstDayOfWeek

<?php
ini_set('date.timezone', 'UTC');

$cal1 = IntlCalendar::createInstance(NULL, 'es_ES');
var_dump($cal1->getFirstDayOfWeek()); // Monday
$cal1->set(2013, 1 /* February */, 3); // a Sunday
var_dump($cal1->get(IntlCalendar::FIELD_WEEK_OF_YEAR)); // 5

$cal2 = IntlCalendar::createInstance(NULL, 'en_US');
var_dump($cal2->getFirstDayOfWeek()); // Sunday
$cal2->set(2013, 1 /* February */, 3); // a Sunday
var_dump($cal2->get(IntlCalendar::FIELD_WEEK_OF_YEAR)); // 6

以上例程会输出:

int(2)
int(5)
int(1)
int(6)

参见

  • IntlCalendar::setFirstDayOfWeek

IntlCalendar::getGreatestMinimum

Get the largest local minimum value for a field

说明

面向对象风格

public int IntlCalendar::getGreatestMinimum ( int $field )

过程化风格

int intlcal_get_greatest_minimum ( IntlCalendar $cal , int $field )

Returns the largest local minimum for a field. This should be a value larger or equal to that returned by IntlCalendar::getActualMinimum, which is in its turn larger or equal to that returned by IntlCalendar::getMinimum. All these three functions return the same value for the Gregorian calendar.

参数

cal
The IntlCalendar resource.

field
One of the IntlCalendar date/time field constants. These are integer values between 0 and IntlCalendar::FIELD_COUNT.

返回值

An int representing a field value, in the fieldʼs unit, 或者在失败时返回 FALSE.

IntlCalendar::getKeywordValuesForLocale

Get set of locale keyword values

说明

面向对象风格

public static Iterator IntlCalendar::getKeywordValuesForLocale ( string $key , string $locale , bool $commonlyUsed )

过程化风格

Iterator intlcal_get_keyword_values_for_locale ( string $key , string $locale , bool $commonlyUsed )

For a given locale key, get the set of values for that key that would result in a different behavior. For now, only the 'calendar' keyword is supported.

This function requires ICU 4.2 or later.

参数

key
The locale keyword for which relevant values are to be queried. Only 'calendar' is supported.

locale
The locale onto which the keyword/value pair are to be appended.

commonlyUsed
Whether to show only the values commonly used for the specified locale.

返回值

An iterator that yields strings with the locale keyword values 或者在失败时返回 FALSE.

范例

示例 #1 IntlCalendar::getKeyworkValuesForLocale

<?php
print_r(
        iterator_to_array(
                IntlCalendar::getKeywordValuesForLocale(
                        'calendar', 'fa_IR', true)));
print_r(
        iterator_to_array(
                IntlCalendar::getKeywordValuesForLocale(
                        'calendar', 'fa_IR', false)));

以上例程会输出:

Array
(
    [0] => persian
    [1] => gregorian
    [2] => islamic
    [3] => islamic-civil
)
Array
(
    [0] => persian
    [1] => gregorian
    [2] => islamic
    [3] => islamic-civil
    [4] => japanese
    [5] => buddhist
    [6] => roc
    [7] => hebrew
    [8] => chinese
    [9] => indian
    [10] => coptic
    [11] => ethiopic
    [12] => ethiopic-amete-alem
)

IntlCalendar::getLeastMaximum

Get the smallest local maximum for a field

说明

面向对象风格

public int IntlCalendar::getLeastMaximum ( int $field )

过程化风格

int intlcal_get_least_maximum ( IntlCalendar $cal , int $field )

Returns the smallest local maximumw for a field. This should be a value smaller or equal to that returned by IntlCalendar::getActualMaxmimum, which is in its turn smaller or equal to that returned by IntlCalendar::getMaximum.

参数

cal
The IntlCalendar resource.

field
One of the IntlCalendar date/time field constants. These are integer values between 0 and IntlCalendar::FIELD_COUNT.

返回值

An int representing a field value in the fieldʼs unit 或者在失败时返回 FALSE.

范例

示例 #1 Maxima examples

<?php
ini_set('date.timezone', 'UTC');
ini_set('intl.default_locale', 'it_IT');

$cal = new IntlGregorianCalendar(2013, 3 /* April */, 6);
var_dump(
    $cal->getLeastMaximum(IntlCalendar::FIELD_DAY_OF_MONTH),  // 28
    $cal->getActualMaximum(IntlCalendar::FIELD_DAY_OF_MONTH), // 30
    $cal->getMaximum(IntlCalendar::FIELD_DAY_OF_MONTH)        // 31
);

以上例程会输出:

int(28)
int(30)
int(31)

参见

  • IntlCalendar::getActualMaximum
  • IntlCalendar::getMaximum
  • IntlCalendar::getGreatestMinimum

IntlCalendar::getLocale

Get the locale associated with the object

说明

面向对象风格

public string IntlCalendar::getLocale ( int $localeType )

过程化风格

string intlcal_get_locale ( IntlCalendar $cal , int $localeType )

Returns the locale used by this calendar object.

参数

cal
The IntlCalendar resource.

localeType
Whether to fetch the actual locale (the locale from which the calendar data originates, with Locale::ACTUAL_LOCALE) or the valid locale, i.e., the most specific locale supported by ICU relatively to the requested locale – see Locale::VALID_LOCALE. From the most general to the most specific, the locales are ordered in this fashion – actual locale, valid locale, requested locale.

返回值

A locale string 或者在失败时返回 FALSE.

范例

示例 #1 IntlCalendar::getLocale

<?php
$cal = IntlCalendar::createInstance(IntlTimeZone::getGMT(), 'en_US_CALIFORNIA');
var_dump(
    $cal->getLocale(Locale::ACTUAL_LOCALE),
    $cal->getLocale(Locale::VALID_LOCALE)
);

以上例程会输出:

string(2) "en"
string(5) "en_US"

IntlCalendar::getMaximum

Get the global maximum value for a field

说明

面向对象风格

public int IntlCalendar::getMaximum ( int $field )

过程化风格

int intlcal_get_maximum ( IntlCalendar $cal , int $field )

Gets the global maximum for a field, in this specific calendar. This value is larger or equal to that returned by IntlCalendar::getActualMaximum, which is in its turn larger or equal to that returned by IntlCalendar::getLeastMaximum.

参数

cal
The IntlCalendar resource.

field
One of the IntlCalendar date/time field constants. These are integer values between 0 and IntlCalendar::FIELD_COUNT.

返回值

An int representing a field value in the fieldʼs unit 或者在失败时返回 FALSE.

参见

  • IntlCalendar::getActualMaximum
  • IntlCalendar::getLeastMaximum
  • IntlCalendar::getMinimum

IntlCalendar::getMinimalDaysInFirstWeek

Get minimal number of days the first week in a year or month can have

说明

面向对象风格

public int IntlCalendar::getMinimalDaysInFirstWeek ( void )

过程化风格

int intlcal_get_minimal_days_in_first_week ( IntlCalendar $cal )

Returns the smallest number of days the first week of a year or month must have in the new year or month. For instance, in the Gregorian calendar, if this value is 1, then the first week of the year will necessarily include January 1st, while if this value is 7, then the week with January 1st will be the first week of the year only if the day of the week for January 1st matches the day of the week returned by IntlCalendar::getFirstDayOfWeek; otherwise it will be the previous yearʼs last week.

参数

cal
The IntlCalendar resource.

返回值

An int representing a number of days 或者在失败时返回 FALSE.

范例

示例 #1 IntlCalendar::getMinimalDaysInFirstWeek

<?php
ini_set('date.timezone', 'UTC');
ini_set('intl.default_locale', 'en_US');

$cal = new IntlGregorianCalendar(2013, 0 /* January */, 2);
var_dump(IntlDateFormatter::formatObject($cal, 'cccc')); // Wednesday

var_dump($cal->getMinimalDaysInFirstWeek(), // 1
$cal->getFirstDayofWeek()); // 1 (Sunday)

// Week 1 of 2013
var_dump(IntlDateFormatter::formatObject($cal, "'Week 'w' of 'Y"));

$cal->setMinimalDaysInFirstWeek(4);
// Still Week 1 of 2013 (1st week has 5 days in the new year)
var_dump(IntlDateFormatter::formatObject($cal, "'Week 'w' of 'Y"));

$cal->setMinimalDaysInFirstWeek(6);
// Week 53 of 2012
var_dump(IntlDateFormatter::formatObject($cal, "'Week 'w' of 'Y"));

以上例程会输出:

string(9) "Wednesday"
int(1)
int(1)
string(14) "Week 1 of 2013"
string(14) "Week 1 of 2013"
string(15) "Week 53 of 2012"

IntlCalendar::getMinimum

Get the global minimum value for a field

说明

面向对象风格

public int IntlCalendar::getMinimum ( int $field )

过程化风格

int intlcal_get_minimum ( IntlCalendar $cal , int $field )

Gets the global minimum for a field, in this specific calendar. This value is smaller or equal to that returned by IntlCalendar::getActualMinimum, which is in its turn smaller or equal to that returned by IntlCalendar::getGreatestMinimum. For the Gregorian calendar, these three functions always return the same value (for each field).

参数

cal
The IntlCalendar resource.

field
One of the IntlCalendar date/time field constants. These are integer values between 0 and IntlCalendar::FIELD_COUNT.

返回值

An int representing a value for the given field in the fieldʼs unit 或者在失败时返回 FALSE.

IntlCalendar::getNow

Get number representing the current time

说明

面向对象风格

public static float IntlCalendar::getNow ( void )

过程化风格

float intlcal_get_now ( void )

The number of milliseconds that have passed since the reference date. This number is derived from the system time.

参数

此函数没有参数。

返回值

A float representing a number of milliseconds since the epoch, not counting leap seconds.

范例

示例 #1 IntlCalendar::getNow

<?php
$formatter = IntlDateFormatter::create('es_ES',
        IntlDateFormatter::FULL,
        IntlDateFormatter::FULL,
        'Europe/Madrid');

$val = IntlCalendar::getNow();

var_dump($val);
echo $formatter->format(IntlCalendar::getNow() / 1000.), "\n";

以上例程会输出:

float(1371425814666)
lunes, 17 de junio de 2013 01:36:54 Hora de verano de Europa central

IntlCalendar::getRepeatedWallTimeOption

Get behavior for handling repeating wall time

说明

面向对象风格

public int IntlCalendar::getRepeatedWallTimeOption ( void )

过程化风格

int intlcal_get_repeated_wall_time_option ( IntlCalendar $cal )

Gets the current strategy for dealing with wall times that are repeated whenever the clock is set back during dailight saving time end transitions. The default value is IntlCalendar::WALLTIME_LAST.

This function requires ICU 4.9 or later.

参数

cal
The IntlCalendar resource.

返回值

One of the constants IntlCalendar::WALLTIME_FIRST or IntlCalendar::WALLTIME_LAST.

范例

示例 #1 IntlCalendar::getRepeatedWallTimeOption

<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'en_US');
ini_set('intl.error_level', E_WARNING);

//On October 27th at 0200, the clock goes back 1 hour and from GMT+01 to GMT+00
$cal = new IntlGregorianCalendar(2013, 9 /* October */, 27, 1, 30);

var_dump($cal->getRepeatedWalltimeOption()); // 0 WALLTIME_LAST

$formatter = IntlDateFormatter::create(
    NULL,
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'UTC'
);
var_dump($formatter->format($cal->getTime() / 1000.));

$cal->setRepeatedWalltimeOption(IntlCalendar::WALLTIME_FIRST);
var_dump($cal->getRepeatedWalltimeOption()); // 1 WALLTIME_FIRST
$cal->set(IntlCalendar::FIELD_HOUR_OF_DAY, 1);

var_dump($formatter->format($cal->getTime() / 1000.));

以上例程会输出:

int(0)
string(42) "Sunday, October 27, 2013 at 1:30:00 AM GMT"
int(1)
string(43) "Sunday, October 27, 2013 at 12:30:00 AM GMT"

参见

  • IntlCalendar::getSkippedWallTimeOption
  • IntlCalendar::setSkippedWallTimeOption
  • IntlCalendar::setRepeatedWallTimeOption

IntlCalendar::getSkippedWallTimeOption

Get behavior for handling skipped wall time

说明

面向对象风格

public int IntlCalendar::getSkippedWallTimeOption ( void )

过程化风格

int intlcal_get_skipped_wall_time_option ( IntlCalendar $cal )

Gets the current strategy for dealing with wall times that are skipped whenever the clock is forwarded during dailight saving time start transitions. The default value is IntlCalendar::WALLTIME_LAST.

The calendar must be lenient for this option to have any effect, otherwise attempting to set a non-existing time will cause an error.

This function requires ICU 4.9 or later.

参数

cal
The IntlCalendar resource.

返回值

One of the constants IntlCalendar::WALLTIME_FIRST, IntlCalendar::WALLTIME_LAST or IntlCalendar::WALLTIME_NEXT_VALID.

范例

示例 #1 IntlCalendar::getSkippedWallTimeOption

<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'en_US');
ini_set('intl.error_level', E_WARNING);

//On March 31st at 0100, the clock goes forward 1 hour and from GMT+00 to GMT+01
$cal = new IntlGregorianCalendar(2013, 2 /* March */, 31, 1, 30);

var_dump(
    $cal->isLenient(),               // true
    $cal->getSkippedWalltimeOption() // 0 WALLTIME_LAST
);

$formatter = IntlDateFormatter::create(
    NULL,
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'UTC'
);
var_dump($formatter->format($cal->getTime() / 1000));

$cal->setSkippedWallTimeOption(IntlCalendar::WALLTIME_FIRST);
var_dump($cal->getSkippedWalltimeOption()); // 1 WALLTIME_FIRST
$cal->set(IntlCalendar::FIELD_HOUR_OF_DAY, 1);

var_dump($formatter->format($cal->getTime() / 1000));

$cal->setSkippedWallTimeOption(IntlCalendar::WALLTIME_NEXT_VALID);
var_dump($cal->getSkippedWalltimeOption()); // 2 WALLTIME_NEXT_VALID
$cal->set(IntlCalendar::FIELD_HOUR_OF_DAY, 1);

var_dump($formatter->format($cal->getTime() / 1000));

以上例程会输出:

bool(true)
int(0)
string(40) "Sunday, March 31, 2013 at 1:30:00 AM GMT"
int(1)
string(41) "Sunday, March 31, 2013 at 12:30:00 AM GMT"
int(2)
string(40) "Sunday, March 31, 2013 at 1:00:00 AM GMT"

参见

  • IntlCalendar::getRepeatedWallTimeOption
  • IntlCalendar::setSkippedWallTimeOption
  • IntlCalendar::setRepeatedWallTimeOption

IntlCalendar::getTime

Get time currently represented by the object

说明

面向对象风格

public float IntlCalendar::getTime ( void )

过程化风格

float intlcal_get_time ( IntlCalendar $cal )

Returns the time associated with this object, expressed as the number of milliseconds since the epoch.

参数

cal
The IntlCalendar resource.

返回值

A float representing the number of milliseconds elapsed since the reference time (1 Jan 1970 00:00:00 UTC).

范例

示例 #1 IntlCalendar::getTime

<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'en_US');

$cal = new IntlGregorianCalendar(2013, 4 /* May */, 1, 0, 0, 0);
$time = $cal->getTime();
var_dump($time, $time / 1000 == strtotime('2013-05-01 00:00:00')); //true

以上例程会输出:

float(1367362800000)
bool(true)

参见

  • IntlCalendar::getNow

IntlCalendar::getTimeZone

Get the objectʼs timezone

说明

面向对象风格

public IntlTimeZone IntlCalendar::getTimeZone ( void )

过程化风格

IntlTimeZone intlcal_get_time_zone ( IntlCalendar $cal )

Returns the IntlTimeZone object associated with this calendar.

参数

cal
The IntlCalendar resource.

返回值

An IntlTimeZone object corresponding to the one used internally in this object.

范例

示例 #1 IntlCalendar::getTimeZone

<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'en_US');

$cal = IntlCalendar::createInstance();
print_r($cal->getTimeZone());

$cal->setTimeZone('UTC');
print_r($cal->getTimeZone());

$cal = IntlCalendar::fromDateTime('2012-01-01 00:00:00 GMT+03:33');
print_r($cal->getTimeZone());

以上例程会输出:

IntlTimeZone Object
(
    [valid] => 1
    [id] => Europe/Lisbon
    [rawOffset] => 0
    [currentOffset] => 3600000
)
IntlTimeZone Object
(
    [valid] => 1
    [id] => UTC
    [rawOffset] => 0
    [currentOffset] => 0
)
IntlTimeZone Object
(
    [valid] => 1
    [id] => GMT+03:33
    [rawOffset] => 12780000
    [currentOffset] => 12780000
)

参见

  • IntlCalendar::setTimeZone
  • IntlCalendar::createInstance
  • IntlGregorianCalendar::__construct

IntlCalendar::getType

Get the calendar type

说明

面向对象风格

public string IntlCalendar::getType ( void )

过程化风格

string intlcal_get_type ( IntlCalendar $cal )

A string describing the type of this calendar. This is one of the valid values for the calendar keyword value 'calendar'.

参数

cal
The IntlCalendar resource.

返回值

A string representing the calendar type, such as 'gregorian', 'islamic', etc.

范例

示例 #1 IntlCalendar::getType

<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'en_US');

$cal = IntlCalendar::createInstance(NULL, '@calendar=ethiopic-amete-alem');
var_dump($cal->getType());

$cal = new IntlGregorianCalendar();
var_dump($cal->getType());

以上例程会输出:

string(19) "ethiopic-amete-alem"
string(9) "gregorian"

IntlCalendar::getWeekendTransition

Get time of the day at which weekend begins or ends

说明

面向对象风格

public int IntlCalendar::getWeekendTransition ( string $dayOfWeek )

过程化风格

int intlcal_get_weekend_transition ( IntlCalendar $cal , string $dayOfWeek )

Returns the number of milliseconds after midnight at which the weekend begins or ends.

This is only applicable for days of the week for which IntlCalendar::getDayOfWeekType returns either IntlCalendar::DOW_TYPE_WEEKEND_OFFSET or IntlCalendar::DOW_TYPE_WEEKEND_CEASE. Calling this function for other days of the week is an error condition.

This function requires ICU 4.4 or later.

参数

cal
The IntlCalendar resource.

dayOfWeek
One of the constants IntlCalendar::DOW_SUNDAY, IntlCalendar::DOW_MONDAY, …, IntlCalendar::DOW_SATURDAY.

返回值

The number of milliseconds into the day at which the weekend begins or ends 或者在失败时返回 FALSE.

范例

See example on IntlCalendar::getDayOfWeekType.

IntlCalendar::inDaylightTime

Whether the objectʼs time is in Daylight Savings Time

说明

面向对象风格

public bool IntlCalendar::inDaylightTime ( void )

过程化风格

bool intlcal_in_daylight_time ( IntlCalendar $cal )

Whether, for the instant represented by this object and for this objectʼs timezone, daylight saving time is in place.

参数

cal
The IntlCalendar resource.

返回值

Returns TRUE if the date is in Daylight Savings Time, FALSE otherwise. The value FALSE may also be returned on failure, for instance after specifying invalid field values on non-lenient mode; use exceptions or query intl_get_error_code to disambiguate.

范例

示例 #1 IntlCalendar::inDaylightTime

<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'pt_PT');

$cal = new IntlGregorianCalendar(2013, 6 /* July */, 1, 4, 56, 31);
var_dump($cal->inDaylightTime()); // true
$cal->set(IntlCalendar::FIELD_MONTH, 11 /* December */);
var_dump($cal->inDaylightTime()); // false

//DST end transition on 2013-10-27 at 0200 (wall time back 1 hour)
$cal = new IntlGregorianCalendar(2013, 9 /* October */, 27, 1, 30, 0);

var_dump($cal->inDaylightTime()); // false (default WALLTIME_LAST)

$cal->setRepeatedWallTimeOption(IntlCalendar::WALLTIME_FIRST);
$cal->set(IntlCalendar::FIELD_HOUR_OF_DAY, 1); // force time recalculation
var_dump($cal->inDaylightTime()); // true

IntlCalendar::isEquivalentTo

Whether another calendar is equal but for a different time

说明

面向对象风格

public bool IntlCalendar::isEquivalentTo ( IntlCalendar $other )

过程化风格

bool intlcal_is_equivalent_to ( IntlCalendar $cal , IntlCalendar $other )

Returns whether this and the given object are equivalent for all purposes except as to the time they have set. The locales do not have to match, as long as no change in behavior results from such mismatch. This includes the timezone, whether the lenient mode is set, the repeated and skipped wall time settings, the days of the week when the weekend starts and ceases and the times where such transitions occur. It may also include other calendar specific settings, such as the Gregorian/Julian transition instant.

参数

cal
The IntlCalendar resource.

other
The other calendar against which the comparison is to be made.

返回值

Assuming there are no argument errors, returns TRUE if the calendars are equivalent except possibly for their set time.

范例

示例 #1 IntlCalendar::isEquivalentTo

<?php
$cal1 = IntlCalendar::createInstance('Europe/Lisbon', 'pt_PT');
$cal2 = IntlCalendar::createInstance('Europe/Lisbon', 'es_ES');
$cal2->clear();

var_dump($cal1->isEquivalentTo($cal2)); // true

$cal3 = IntlCalendar::createInstance('Europe/Lisbon', 'en_US');
var_dump($cal1->isEquivalentTo($cal3)); // false
var_dump($cal1->getFirstDayOfWeek(),    // 2 (Monday)
$cal3->getFirstDayOfWeek());            // 1 (Sunday)

以上例程会输出:

bool(true)
bool(false)
int(2)
int(1)

参见

  • IntlCalendar::equals

IntlCalendar::isLenient

Whether date/time interpretation is in lenient mode

说明

面向对象风格

public bool IntlCalendar::isLenient ( void )

过程化风格

bool intlcal_is_lenient ( IntlCalendar $cal )

Returns whether the current date/time interpretations is lenient (the default). If that is case, some out of range values for fields will be accepted instead of raising an error.

参数

cal
The IntlCalendar resource.

返回值

A bool representing whether the calendar is set to lenient mode.

范例

示例 #1 IntlCalendar::isLenient

<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'pt_PT');
ini_set('intl.use_exceptions', '1');

$cal = new IntlGregorianCalendar(2013, 6 /* July */, 1);
var_dump(IntlDateFormatter::formatObject($cal), // 01/07/2013, 00:00:00
$cal->isLenient()); // true

$cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 33);
var_dump(IntlDateFormatter::formatObject($cal)); // 02/08/2013, 00:00:00

$cal->setLenient(false);
var_dump($cal->isLenient()); // false
$cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 33);
var_dump(IntlDateFormatter::formatObject($cal)); // error

以上例程会输出:

string(20) "01/07/2013, 00:00:00"
bool(true)
string(20) "02/08/2013, 00:00:00"
bool(false)

Fatal error: Uncaught exception 'IntlException' with message 'datefmt_format_object: error obtaining instant from IntlCalendar' in /home/foobar/example.php:16
Stack trace:
#0 /home/foobar/example.php(16): IntlDateFormatter::formatObject(Object(IntlGregorianCalendar))
#1 {main}
  thrown in /home/foobar/example.php on line 16

IntlCalendar::isSet

Whether a field is set

说明

面向对象风格

public bool IntlCalendar::isSet ( int $field )

过程化风格

bool intlcal_is_set ( IntlCalendar $cal , int $field )

Returns whether a field is set (as opposed to clear). Set fields take priority over unset fields and their default values when the date/time is being calculated. Fields set later take priority over fields set earlier.

参数

cal
The IntlCalendar resource.

field
One of the IntlCalendar date/time field constants. These are integer values between 0 and IntlCalendar::FIELD_COUNT.

返回值

Assuming there are no argument errors, returns TRUE if the field is set.

范例

See the example on IntlCalendar::clear.

参见

  • IntlCalendar::clear
  • IntlCalendar::set

IntlCalendar::isWeekend

Whether a certain date/time is in the weekend

说明

面向对象风格

public bool IntlCalendar::isWeekend ([ float $date = NULL ] )

过程化风格

bool intlcal_is_weekend ( IntlCalendar $cal [, float $date = NULL ] )

Returns whether either the obejctʼs current time or the provided timestamp occur during a weekend in this objectʼs calendar system.

This function requires ICU 4.4 or later.

参数

cal
The IntlCalendar resource.

date
An optional timestamp representing the number of milliseconds since the epoch, excluding leap seconds. If NULL, this objectʼs current time is used instead.

返回值

A bool indicating whether the given or this objectʼs time occurs in a weekend.

The value FALSE may also be returned on failure, for instance after giving a date out of bounds on non-lenient mode; use exceptions or query intl_get_error_code to disambiguate.

范例

示例 #1 IntlCalendar::isWeekend

<?php
ini_set('date.timezone', 'Europe/Lisbon');

$cal = new IntlGregorianCalendar(NULL, 'en_US');
$cal->set(2013, 6 /* July */, 7); // a Sunday 

var_dump($cal->isWeekend()); // true
var_dump($cal->isWeekend(strtotime('2013-07-01 00:00:00'))); // false, Monday

$cal = new IntlGregorianCalendar(NULL, 'ar_SA');
$cal->set(2013, 6 /* July */, 7); // a Sunday 
var_dump($cal->isWeekend()); // false, Sunday not in weekend in this calendar

参见

  • IntlCalendar::getDayOfWeekType
  • IntlCalendar::getWeekendTransition

IntlCalendar::roll

Add value to field without carrying into more significant fields

说明

面向对象风格

public bool IntlCalendar::roll ( int $field , mixed $amountOrUpOrDown )

过程化风格

bool intlcal_roll ( IntlCalendar $cal , int $field , mixed $amountOrUpOrDown )

Adds a (signed) amount to a field. The difference with respect to IntlCalendar::add is that when the field value overflows, it does not carry into more significant fields.

参数

cal
The IntlCalendar resource.

field
One of the IntlCalendar date/time field constants. These are integer values between 0 and IntlCalendar::FIELD_COUNT.

amountOrUpOrDown
The (signed) amount to add to the field, TRUE for rolling up (adding 1), or FALSE for rolling down (subtracting 1).

返回值

Returns TRUE on success or FALSE on failure.

范例

示例 #1 IntlCalendar::roll

<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'pt_PT');

$cal = new IntlGregorianCalendar(2013, 5 /* June */, 30);

$cal->add(IntlCalendar::FIELD_DAY_OF_MONTH, 1);
var_dump(IntlDateFormatter::formatObject($cal)); // "01/07/2013, 00:00:00"

$cal->set(2013, 5 /* June */, 30);
$cal->roll(IntlCalendar::FIELD_DAY_OF_MONTH, true); // roll up, same as rolling +1
var_dump(IntlDateFormatter::formatObject($cal)); // "01/06/2013, 00:00:00"

以上例程会输出:

string(20) "01/07/2013, 00:00:00"
string(20) "01/06/2013, 00:00:00"

参见

  • IntlCalendar::add
  • IntlCalendar::set

IntlCalendar::set

Set a time field or several common fields at once

说明

面向对象风格

public bool IntlCalendar::set ( int $field , int $value )

public bool IntlCalendar::set ( int $year , int $month [, int $dayOfMonth = NULL [, int $hour = NULL [, int $minute = NULL [, int $second = NULL ]]]] )

过程化风格

bool intlcal_set ( IntlCalendar $cal , int $field , int $value )

bool intlcal_set ( IntlCalendar $cal , int $year , int $month [, int $dayOfMonth = NULL [, int $hour = NULL [, int $minute = NULL [, int $second = NULL ]]]] )

Sets either a specific field to the given value, or sets at once several common fields. The range of values that are accepted depend on whether the calendar is using the lenient mode.

For fields that conflict, the fields that are set later have priority.

This method cannot be called with exactly four arguments.

参数

cal
The IntlCalendar resource.

field
One of the IntlCalendar date/time field constants. These are integer values between 0 and IntlCalendar::FIELD_COUNT.

value
The new value of the given field.

year
The new value for IntlCalendar::FIELD_YEAR.

month
The new value for IntlCalendar::FIELD_MONTH.

dayOfMonth
The new value for IntlCalendar::FIELD_DAY_OF_MONTH. The month sequence is zero-based, i.e., January is represented by 0, February by 1, …, December is 11 and Undecember (if the calendar has it) is 12.

hour
The new value for IntlCalendar::FIELD_HOUR_OF_DAY.

minute
The new value for IntlCalendar::FIELD_MINUTE.

second
The new value for IntlCalendar::FIELD_SECOND.

返回值

Returns TRUE on success and FALSE on failure.

范例

示例 #1 IntlCalendar::set

<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'pt_PT');

//Calls made later have priority
$cal = new IntlGregorianCalendar(2013, 6 /* July */, 1);
$cal->set(IntlCalendar::FIELD_YEAR, 2012);
$cal->set(IntlCalendar::FIELD_EXTENDED_YEAR, 2011);
var_dump(IntlDateFormatter::formatObject($cal));


$cal = new IntlGregorianCalendar(2013, 6 /* July */, 1);
$cal->set(IntlCalendar::FIELD_YEAR, 2012);
$cal->set(IntlCalendar::FIELD_EXTENDED_YEAR, 2011);
//the time has not been recalculated yet. If we clear the extended year,
//the year set before will be used
$cal->clear(IntlCalendar::FIELD_EXTENDED_YEAR);
var_dump(IntlDateFormatter::formatObject($cal));

以上例程会输出:

string(20) "01/07/2011, 00:00:00"
string(20) "01/07/2012, 00:00:00"

参见

  • IntlCalendar::get
  • IntlCalendar::add
  • IntlCalendar::roll

IntlCalendar::setFirstDayOfWeek

Set the day on which the week is deemed to start

说明

面向对象风格

public bool IntlCalendar::setFirstDayOfWeek ( int $dayOfWeek )

过程化风格

bool intlcal_set_first_day_of_week ( IntlCalendar $cal , int $dayOfWeek )

Defines the day of week deemed to start the week. This affects the behavior of fields that depend on the concept of week start and end such as IntlCalendar::FIELD_WEEK_OF_YEAR and IntlCalendar::FIELD_YEAR_WOY.

参数

cal
The IntlCalendar resource.

dayOfWeek
One of the constants IntlCalendar::DOW_SUNDAY, IntlCalendar::DOW_MONDAY, …, IntlCalendar::DOW_SATURDAY.

返回值

Returns TRUE on success. Failure can only happen due to invalid parameters.

范例

示例 #1 IntlCalendar::setFirstDayOfWeek

<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'es_ES');

$cal = IntlCalendar::createInstance();
$cal->set(2013, 5 /* June */, 30); // A Sunday

var_dump($cal->getFirstDayOfWeek()); // 2 (Monday)

echo IntlDateFormatter::formatObject($cal, <<<EOD
'local day of week: 'cc'
week of month    : 'W'
week of year     : 'ww
EOD
), "\n";

$cal->setFirstDayOfWeek(IntlCalendar::DOW_SUNDAY);

echo IntlDateFormatter::formatObject($cal, <<<EOD
'local day of week: 'cc'
week of month    : 'W'
week of year     : 'ww
EOD
), "\n";

以上例程会输出:

int(2)
local day of week: 7
week of month    : 4
week of year     : 26
local day of week: 1
week of month    : 5
week of year     : 27

IntlCalendar::setLenient

Set whether date/time interpretation is to be lenient

说明

面向对象风格

public bool IntlCalendar::setLenient ( bool $isLenient )

过程化风格

bool intlcal_set_lenient ( IntlCalendar $cal , bool $isLenient )

Defines whether the calendar is ‘lenient mode’. In such a mode, some of out-of-bounds values for some fields are accepted, the behavior being similar to that of IntlCalendar::add (i.e., the value wraps around, carrying into more significant fields each time). If the lenient mode is off, then such values will generate an error.

参数

cal
The IntlCalendar resource.

isLenient
Use TRUE to activate the lenient mode; FALSE otherwise.

返回值

Returns TRUE on success. Failure can only happen due to invalid parameters.

范例

See the example in IntlCalendar::isLenient.

IntlCalendar::setMinimalDaysInFirstWeek

Set minimal number of days the first week in a year or month can have

说明

面向对象风格

public bool IntlCalendar::setMinimalDaysInFirstWeek ( int $minimalDays )

过程化风格

bool intlcal_get_minimal_days_in_first_week ( IntlCalendar $cal , int $minimalDays )

Sets the smallest number of days the first week of a year or month must have in the new year or month. For instance, in the Gregorian calendar, if this value is 1, then the first week of the year will necessarily include January 1st, while if this value is 7, then the week with January 1st will be the first week of the year only if the day of the week for January 1st matches the day of the week returned by IntlCalendar::getFirstDayOfWeek; otherwise it will be the previous yearʼs last week.

参数

cal
The IntlCalendar resource.

minimalDays
The number of minimal days to set.

返回值

TRUE on success, FALSE on failure.

IntlCalendar::setRepeatedWallTimeOption

Set behavior for handling repeating wall times at negative timezone offset transitions

说明

面向对象风格

public bool IntlCalendar::setRepeatedWallTimeOption ( int $wallTimeOption )

过程化风格

bool intlcal_set_repeated_wall_time_option ( IntlCalendar $cal , int $wallTimeOption )

Sets the current strategy for dealing with wall times that are repeated whenever the clock is set back during dailight saving time end transitions. The default value is IntlCalendar::WALLTIME_LAST (take the post-DST instant). The other possible value is IntlCalendar::WALLTIME_FIRST (take the instant that occurs during DST).

This function requires ICU 4.9 or later.

参数

cal
The IntlCalendar resource.

wallTimeOption
One of the constants IntlCalendar::WALLTIME_FIRST or IntlCalendar::WALLTIME_LAST.

返回值

Returns TRUE on success. Failure can only happen due to invalid parameters.

范例

See the example on IntlCalendar::getRepeatedWallTimeOption.

参见

  • intlCalendar::getRepeatedWallTimeOption
  • intlCalendar::setSkippedWallTimeOption
  • intlCalendar::getSkippedWallTimeOption

IntlCalendar::setSkippedWallTimeOption

Set behavior for handling skipped wall times at positive timezone offset transitions

说明

面向对象风格

public bool IntlCalendar::setSkippedWallTimeOption ( int $wallTimeOption )

过程化风格

bool intlcal_set_skipped_wall_time_option ( IntlCalendar $cal , int $wallTimeOption )

Sets the current strategy for dealing with wall times that are skipped whenever the clock is forwarded during dailight saving time start transitions. The default value is IntlCalendar::WALLTIME_LAST (take it as being the same instant as the one when the wall time is one hour more). Alternative values are IntlCalendar::WALLTIME_FIRST (same instant as the one with a wall time of one hour less) and IntlCalendar::WALLTIME_NEXT_VALID (same instant as when DST begins).

This affects only the instant represented by the calendar (as reported by IntlCalendar::getTime), the field values will not be rewritten accordingly.

The calendar must be lenient for this option to have any effect, otherwise attempting to set a non-existing time will cause an error.

This function requires ICU 4.9 or later.

参数

cal
The IntlCalendar resource.

wallTimeOption
One of the constants IntlCalendar::WALLTIME_FIRST, IntlCalendar::WALLTIME_LAST or IntlCalendar::WALLTIME_NEXT_VALID.

返回值

Returns TRUE on success. Failure can only happen due to invalid parameters.

范例

See the example on IntlCalendar::getSkippedWallTimeOption.

参见

  • intlCalendar::getSkippedWallTimeOption
  • intlCalendar::setRepeatedWallTimeOption
  • intlCalendar::getRepeatedWallTimeOption

IntlCalendar::setTime

Set the calendar time in milliseconds since the epoch

说明

面向对象风格

public bool IntlCalendar::setTime ( float $date )

过程化风格

bool intlcal_set_time ( IntlCalendar $cal , float $date )

Sets the instant represented by this object. The instant is represented by a float whose value should be an integer number of milliseconds since the epoch (1 Jan 1970 00:00:00.000 UTC), ignoring leap seconds. All the field values will be recalculated accordingly.

参数

cal
The IntlCalendar resource.

date
An instant represented by the number of number of milliseconds between such instant and the epoch, ignoring leap seconds.

返回值

Returns TRUE on success and FALSE on failure.

范例

示例 #1 IntlCalendar::setTime

<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'fr_FR');

$cal = new IntlGregorianCalendar(2013, 5 /* May */, 1, 12, 0, 0);

echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";

/* In Europe/Lisbon, on 2013-10-27 at 0200, the clock goes back one hour and
   the timezone from UTC+01 to UTC+00 */

$cal->setTime(strtotime('2013-10-27 00:30:00 UTC') * 1000.);

echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";

$cal->setTime(strtotime('2013-10-27 01:30:00 UTC') * 1000.);

echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";

以上例程会输出:

samedi 1 juin 2013 12:00:00 heure avancée d’Europe de l’Ouest
dimanche 27 octobre 2013 01:30:00 heure avancée d’Europe de l’Ouest
dimanche 27 octobre 2013 01:30:00 heure normale d’Europe de l’Ouest

IntlCalendar::setTimeZone

Set the timezone used by this calendar

说明

面向对象风格

public bool IntlCalendar::setTimeZone ( mixed $timeZone )

过程化风格

bool intlcal_set_time_zone ( IntlCalendar $cal , mixed $timeZone )

Defines a new timezone for this calendar. The time represented by the object is preserved to the detriment of the field values.

参数

cal
The IntlCalendar resource.

timeZone
The new timezone to be used by this calendar. It can be specified in the following ways:

  • NULL, in which case the default timezone will be used, as specified in the ini setting date.timezone or through the function date_default_timezone_set and as returned by date_default_timezone_get.

  • An IntlTimeZone, which will be used directly.

  • A DateTimeZone. Its identifier will be extracted and an ICU timezone object will be created; the timezone will be backed by ICUʼs database, not PHPʼs.

  • A string, which should be a valid ICU timezone identifier. See IntlTimeZone::createTimeZoneIDEnumeration. Raw offsets such as "GMT+08:30" are also accepted.

返回值

Returns TRUE on success and FALSE on failure.

范例

示例 #1 IntlCalendar::setTimeZone

<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'es_ES');

$cal = new IntlGregorianCalendar(2013, 5 /* May */, 1, 12, 0, 0);

echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
echo "(instant {$cal->getTime()})\n";

$cal->setTimeZone(IntlTimeZone::getGMT());
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
echo "(instant {$cal->getTime()})\n";

$cal->setTimeZone('GMT+03:33');
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
echo "(instant {$cal->getTime()})\n";

以上例程会输出:

sábado, 1 de junio de 2013 12:00:00 Hora de verano de Europa occidental
(instant 1370084400000)
sábado, 1 de junio de 2013 11:00:00 GMT
(instant 1370084400000)
sábado, 1 de junio de 2013 14:33:00 GMT+03:33
(instant 1370084400000)

IntlCalendar::toDateTime

Convert an IntlCalendar into a DateTime object

说明

面向对象风格

public DateTime IntlCalendar::toDateTime ( void )

过程化风格

DateTime intlcal_to_date_time ( IntlCalendar $cal )

Create a DateTime object that represents the same instant (up to second precision, with a rounding error of less than 1 second) and has an analog timezone to this object (the difference being DateTimeʼs timezone will be backed by PHPʼs timezone while IntlCalendarʼs timezone is backed by ICUʼs).

参数

cal
The IntlCalendar resource.

返回值

A DateTime object with the same timezone as this object (though using PHPʼs database instead of ICUʼs) and the same time, except for the smaller precision (second precision instead of millisecond). Returns FALSE on failure.

范例

示例 #1 IntlCalendar::toDateTime

<?php
ini_set('date.timezone', 'UTC');
ini_set('intl.default_locale', 'pt_PT');

$cal = IntlCalendar::createInstance('Europe/Lisbon'); //current time

$dt = $cal->toDateTime();
print_r($dt);

以上例程会输出:

DateTime Object
(
    [date] => 2013-07-02 00:29:13
    [timezone_type] => 3
    [timezone] => Europe/Lisbon
)

参见

  • IntlCalendar::fromDateTime
  • IntlCalendar::getTime
  • IntlCalendar::createInstance
  • DateTime:__construct

简介

类摘要

IntlGregorianCalendar

class IntlGregorianCalendar extends IntlCalendar {

/* 继承的常量 */

const integer IntlCalendar::FIELD_ERA = 0 ;

const integer IntlCalendar::FIELD_YEAR = 1 ;

const integer IntlCalendar::FIELD_MONTH = 2 ;

const integer IntlCalendar::FIELD_WEEK_OF_YEAR = 3 ;

const integer IntlCalendar::FIELD_WEEK_OF_MONTH = 4 ;

const integer IntlCalendar::FIELD_DATE = 5 ;

const integer IntlCalendar::FIELD_DAY_OF_YEAR = 6 ;

const integer IntlCalendar::FIELD_DAY_OF_WEEK = 7 ;

const integer IntlCalendar::FIELD_DAY_OF_WEEK_IN_MONTH = 8 ;

const integer IntlCalendar::FIELD_AM_PM = 9 ;

const integer IntlCalendar::FIELD_HOUR = 10 ;

const integer IntlCalendar::FIELD_HOUR_OF_DAY = 11 ;

const integer IntlCalendar::FIELD_MINUTE = 12 ;

const integer IntlCalendar::FIELD_SECOND = 13 ;

const integer IntlCalendar::FIELD_MILLISECOND = 14 ;

const integer IntlCalendar::FIELD_ZONE_OFFSET = 15 ;

const integer IntlCalendar::FIELD_DST_OFFSET = 16 ;

const integer IntlCalendar::FIELD_YEAR_WOY = 17 ;

const integer IntlCalendar::FIELD_DOW_LOCAL = 18 ;

const integer IntlCalendar::FIELD_EXTENDED_YEAR = 19 ;

const integer IntlCalendar::FIELD_JULIAN_DAY = 20 ;

const integer IntlCalendar::FIELD_MILLISECONDS_IN_DAY = 21 ;

const integer IntlCalendar::FIELD_IS_LEAP_MONTH = 22 ;

const integer IntlCalendar::FIELD_FIELD_COUNT = 23 ;

const integer IntlCalendar::FIELD_DAY_OF_MONTH = 5 ;

const integer IntlCalendar::DOW_SUNDAY = 1 ;

const integer IntlCalendar::DOW_MONDAY = 2 ;

const integer IntlCalendar::DOW_TUESDAY = 3 ;

const integer IntlCalendar::DOW_WEDNESDAY = 4 ;

const integer IntlCalendar::DOW_THURSDAY = 5 ;

const integer IntlCalendar::DOW_FRIDAY = 6 ;

const integer IntlCalendar::DOW_SATURDAY = 7 ;

const integer IntlCalendar::DOW_TYPE_WEEKDAY = 0 ;

const integer IntlCalendar::DOW_TYPE_WEEKEND = 1 ;

const integer IntlCalendar::DOW_TYPE_WEEKEND_OFFSET = 2 ;

const integer IntlCalendar::DOW_TYPE_WEEKEND_CEASE = 3 ;

const integer IntlCalendar::WALLTIME_FIRST = 1 ;

const integer IntlCalendar::WALLTIME_LAST = 0 ;

const integer IntlCalendar::WALLTIME_NEXT_VALID = 2 ;

/* 方法 */

public __construct ([ IntlTimeZone $tz [, string $locale ]] )

public float getGregorianChange ( void )

public bool isLeapYear ( int $year )

public bool setGregorianChange ( float $date )

/* 继承的方法 */

public bool IntlCalendar::add ( int $field , int $amount )

bool intlcal_add ( IntlCalendar $cal , int $field , int $amount )

public bool IntlCalendar::after ( IntlCalendar $other )

bool intlcal_after ( IntlCalendar $cal , IntlCalendar $other )

public bool IntlCalendar::before ( IntlCalendar $other )

bool intlcal_before ( IntlCalendar $cal , IntlCalendar $other )

public bool IntlCalendar::clear ([ int $field = NULL ] )

bool intlcal_clear ( IntlCalendar $cal [, int $field = NULL ] )

private IntlCalendar::__construct ( void )

public static IntlCalendar IntlCalendar::createInstance ([ mixed $timeZone = NULL [, string $locale = "" ]] )

IntlCalendar intlcal_create_instance ([ mixed $timeZone = NULL [, string $locale = "" ]] )

public bool IntlCalendar::equals ( IntlCalendar $other )

bool intlcal_equals ( IntlCalendar $cal , IntlCalendar $other )

public int IntlCalendar::fieldDifference ( float $when , int $field )

int intlcal_field_difference ( IntlCalendar $cal , float $when , int $field )

public static IntlCalendar IntlCalendar::fromDateTime ( mixed $dateTime )

IntlCalendar intlcal_from_date_time ( mixed $dateTime )

public int IntlCalendar::get ( int $field )

int intlcal_get ( IntlCalendar $cal , int $field )

public int IntlCalendar::getActualMaximum ( int $field )

int intlcal_get_actual_maximum ( IntlCalendar $cal , int $field )

public int IntlCalendar::getActualMinimum ( int $field )

int intlcal_get_actual_minimum ( IntlCalendar $cal , int $field )

public static array IntlCalendar::getAvailableLocales ( void )

array intlcal_get_available_locales ( void )

public int IntlCalendar::getDayOfWeekType ( int $dayOfWeek )

int intlcal_get_day_of_week_type ( IntlCalendar $cal , int $dayOfWeek )

public int IntlCalendar::getErrorCode ( void )

public string IntlCalendar::getErrorMessage ( void )

public int IntlCalendar::getFirstDayOfWeek ( void )

int intlcal_get_first_day_of_week ( IntlCalendar $cal )

public int IntlCalendar::getGreatestMinimum ( int $field )

int intlcal_get_greatest_minimum ( IntlCalendar $cal , int $field )

public static Iterator IntlCalendar::getKeywordValuesForLocale ( string $key , string $locale , bool $commonlyUsed )

Iterator intlcal_get_keyword_values_for_locale ( string $key , string $locale , bool $commonlyUsed )

public int IntlCalendar::getLeastMaximum ( int $field )

int intlcal_get_least_maximum ( IntlCalendar $cal , int $field )

public string IntlCalendar::getLocale ( int $localeType )

string intlcal_get_locale ( IntlCalendar $cal , int $localeType )

public int IntlCalendar::getMaximum ( int $field )

int intlcal_get_maximum ( IntlCalendar $cal , int $field )

public int IntlCalendar::getMinimalDaysInFirstWeek ( void )

int intlcal_get_minimal_days_in_first_week ( IntlCalendar $cal )

public int IntlCalendar::getMinimum ( int $field )

int intlcal_get_minimum ( IntlCalendar $cal , int $field )

public static float IntlCalendar::getNow ( void )

float intlcal_get_now ( void )

public int IntlCalendar::getRepeatedWallTimeOption ( void )

int intlcal_get_repeated_wall_time_option ( IntlCalendar $cal )

public int IntlCalendar::getSkippedWallTimeOption ( void )

int intlcal_get_skipped_wall_time_option ( IntlCalendar $cal )

public float IntlCalendar::getTime ( void )

float intlcal_get_time ( IntlCalendar $cal )

public IntlTimeZone IntlCalendar::getTimeZone ( void )

IntlTimeZone intlcal_get_time_zone ( IntlCalendar $cal )

public string IntlCalendar::getType ( void )

string intlcal_get_type ( IntlCalendar $cal )

public int IntlCalendar::getWeekendTransition ( string $dayOfWeek )

int intlcal_get_weekend_transition ( IntlCalendar $cal , string $dayOfWeek )

public bool IntlCalendar::inDaylightTime ( void )

bool intlcal_in_daylight_time ( IntlCalendar $cal )

public bool IntlCalendar::isEquivalentTo ( IntlCalendar $other )

bool intlcal_is_equivalent_to ( IntlCalendar $cal , IntlCalendar $other )

public bool IntlCalendar::isLenient ( void )

bool intlcal_is_lenient ( IntlCalendar $cal )

public bool IntlCalendar::isSet ( int $field )

bool intlcal_is_set ( IntlCalendar $cal , int $field )

public bool IntlCalendar::isWeekend ([ float $date = NULL ] )

bool intlcal_is_weekend ( IntlCalendar $cal [, float $date = NULL ] )

public bool IntlCalendar::roll ( int $field , mixed $amountOrUpOrDown )

bool intlcal_roll ( IntlCalendar $cal , int $field , mixed $amountOrUpOrDown )

public bool IntlCalendar::set ( int $field , int $value )

public bool IntlCalendar::set ( int $year , int $month [, int $dayOfMonth = NULL [, int $hour = NULL [, int $minute = NULL [, int $second = NULL ]]]] )

bool intlcal_set ( IntlCalendar $cal , int $field , int $value )

bool intlcal_set ( IntlCalendar $cal , int $year , int $month [, int $dayOfMonth = NULL [, int $hour = NULL [, int $minute = NULL [, int $second = NULL ]]]] )

public bool IntlCalendar::setFirstDayOfWeek ( int $dayOfWeek )

bool intlcal_set_first_day_of_week ( IntlCalendar $cal , int $dayOfWeek )

public bool IntlCalendar::setLenient ( bool $isLenient )

bool intlcal_set_lenient ( IntlCalendar $cal , bool $isLenient )

public bool IntlCalendar::setMinimalDaysInFirstWeek ( int $minimalDays )

bool intlcal_get_minimal_days_in_first_week ( IntlCalendar $cal , int $minimalDays )

public bool IntlCalendar::setRepeatedWallTimeOption ( int $wallTimeOption )

bool intlcal_set_repeated_wall_time_option ( IntlCalendar $cal , int $wallTimeOption )

public bool IntlCalendar::setSkippedWallTimeOption ( int $wallTimeOption )

bool intlcal_set_skipped_wall_time_option ( IntlCalendar $cal , int $wallTimeOption )

public bool IntlCalendar::setTime ( float $date )

bool intlcal_set_time ( IntlCalendar $cal , float $date )

public bool IntlCalendar::setTimeZone ( mixed $timeZone )

bool intlcal_set_time_zone ( IntlCalendar $cal , mixed $timeZone )

public DateTime IntlCalendar::toDateTime ( void )

DateTime intlcal_to_date_time ( IntlCalendar $cal )

}

IntlGregorianCalendar::__construct

Create the Gregorian Calendar class

说明

public IntlGregorianCalendar::__construct ([ IntlTimeZone $tz [, string $locale ]] )

public IntlGregorianCalendar::__construct ( int $timeZoneOrYear , int $localeOrMonth , int $dayOfMonth )

public IntlGregorianCalendar::__construct ( int $timeZoneOrYear , int $localeOrMonth , int $dayOfMonth , int $hour , int $minute [, int $second ] )

Warning

本函数还未编写文档,仅有参数列表。

参数

tz

locale

timeZoneOrYear

localeOrMonth

dayOfMonth

hour

minute

second

IntlGregorianCalendar::getGregorianChange

Get the Gregorian Calendar change date

说明

public float IntlGregorianCalendar::getGregorianChange ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

Returns the change date 或者在失败时返回 FALSE.

IntlGregorianCalendar::isLeapYear

Determine if the given year is a leap year

说明

public bool IntlGregorianCalendar::isLeapYear ( int $year )

Warning

本函数还未编写文档,仅有参数列表。

参数

year

返回值

Returns TRUE for leap years, FALSE otherwise and on failure.

IntlGregorianCalendar::setGregorianChange

Set the Gregorian Calendar the change date

说明

public bool IntlGregorianCalendar::setGregorianChange ( float $date )

Warning

本函数还未编写文档,仅有参数列表。

参数

date

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

简介

类摘要

IntlTimeZone

class IntlTimeZone {

/* Constants */

const integer IntlTimeZone::DISPLAY_SHORT = 1 ;

const integer IntlTimeZone::DISPLAY_LONG = 2 ;

/* 方法 */

public static int countEquivalentIDs ( string $zoneId )

public static IntlTimeZone createDefault ( void )

public static IntlIterator createEnumeration ([ mixed $countryOrRawOffset ] )

public static IntlTimeZone createTimeZone ( string $zoneId )

public static IntlIterator createTimeZoneIDEnumeration ( int $zoneType [, string $region [, int $rawOffset ]] )

public static IntlTimeZone fromDateTimeZone ( DateTimeZone $zoneId )

public static string getCanonicalID ( string $zoneId [, bool &$isSystemID ] )

public string getDisplayName ([ bool $isDaylight [, int $style [, string $locale ]]] )

public int getDSTSavings ( void )

public static string getEquivalentID ( string $zoneId , int $index )

public int getErrorCode ( void )

public string getErrorMessage ( void )

public static IntlTimeZone getGMT ( void )

public string getID ( void )

public static string getIDForWindowsID ( string $timezone [, string $region ] )

public int getOffset ( float $date , bool $local , int &$rawOffset , int &$dstOffset )

public int getRawOffset ( void )

public static string getRegion ( string $zoneId )

public static string getTZDataVersion ( void )

public static IntlTimeZone getUnknown ( void )

public static string getWindowsID ( string $timezone )

public bool hasSameRules ( IntlTimeZone $otherTimeZone )

public DateTimeZone toDateTimeZone ( void )

public bool useDaylightTime ( void )

}

预定义常量

IntlTimeZone::DISPLAY_SHORT

IntlTimeZone::DISPLAY_LONG

IntlTimeZone::countEquivalentIDs

Get the number of IDs in the equivalency group that includes the given ID

说明

public static int IntlTimeZone::countEquivalentIDs ( string $zoneId )

Warning

本函数还未编写文档,仅有参数列表。

参数

zoneId

返回值

IntlTimeZone::createDefault

Create a new copy of the default timezone for this host

说明

public static IntlTimeZone IntlTimeZone::createDefault ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlTimeZone::createEnumeration

Get an enumeration over time zone IDs associated with the given country or offset

说明

public static IntlIterator IntlTimeZone::createEnumeration ([ mixed $countryOrRawOffset ] )

Warning

本函数还未编写文档,仅有参数列表。

参数

countryOrRawOffset

返回值

IntlTimeZone::createTimeZone

Create a timezone object for the given ID

说明

public static IntlTimeZone IntlTimeZone::createTimeZone ( string $zoneId )

Warning

本函数还未编写文档,仅有参数列表。

参数

zoneId

返回值

IntlTimeZone::createTimeZoneIDEnumeration

Get an enumeration over system time zone IDs with the given filter conditions

说明

public static IntlIterator IntlTimeZone::createTimeZoneIDEnumeration ( int $zoneType [, string $region [, int $rawOffset ]] )

Warning

本函数还未编写文档,仅有参数列表。

参数

zoneType

region

rawOffset

返回值

Returns IntlIterator 或者在失败时返回 FALSE.

IntlTimeZone::fromDateTimeZone

Create a timezone object from DateTimeZone

说明

public static IntlTimeZone IntlTimeZone::fromDateTimeZone ( DateTimeZone $zoneId )

Warning

本函数还未编写文档,仅有参数列表。

参数

zoneId

返回值

IntlTimeZone::getCanonicalID

Get the canonical system timezone ID or the normalized custom time zone ID for the given time zone ID

说明

public static string IntlTimeZone::getCanonicalID ( string $zoneId [, bool &$isSystemID ] )

Warning

本函数还未编写文档,仅有参数列表。

参数

zoneId

isSystemID

返回值

IntlTimeZone::getDisplayName

Get a name of this time zone suitable for presentation to the user

说明

public string IntlTimeZone::getDisplayName ([ bool $isDaylight [, int $style [, string $locale ]]] )

Warning

本函数还未编写文档,仅有参数列表。

参数

isDaylight

style

locale

返回值

IntlTimeZone::getDSTSavings

Get the amount of time to be added to local standard time to get local wall clock time

说明

public int IntlTimeZone::getDSTSavings ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlTimeZone::getEquivalentID

Get an ID in the equivalency group that includes the given ID

说明

public static string IntlTimeZone::getEquivalentID ( string $zoneId , int $index )

Warning

本函数还未编写文档,仅有参数列表。

参数

zoneId

index

返回值

IntlTimeZone::getErrorCode

intltz_get_error_code

Get last error code on the object

说明

面向对象风格 (method):

public int IntlTimeZone::getErrorCode ( void )

过程化风格:

int intltz_get_error_code ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlTimeZone::getErrorMessage

intltz_get_error_message

Get last error message on the object

说明

面向对象风格 (method):

public string IntlTimeZone::getErrorMessage ( void )

过程化风格:

string intltz_get_error_message ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlTimeZone::getGMT

Create GMT (UTC) timezone

说明

public static IntlTimeZone IntlTimeZone::getGMT ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlTimeZone::getID

Get timezone ID

说明

public string IntlTimeZone::getID ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlTimeZone::getIDForWindowsID

Translate a Windows timezone into a system timezone

说明

public static string IntlTimeZone::getIDForWindowsID ( string $timezone [, string $region ] )

Translates a Windows timezone (e.g. "Pacific Standard Time") into a system timezone (e.g. "America/Los_Angeles").

Note: This function requires ICU version ≥

Warning

本函数还未编写文档,仅有参数列表。

参数

timezone

region

返回值

Returns the system timezone 或者在失败时返回 FALSE.

参见

  • IntlTimeZone::getWindowsID

IntlTimeZone::getOffset

Get the time zone raw and GMT offset for the given moment in time

说明

public int IntlTimeZone::getOffset ( float $date , bool $local , int &$rawOffset , int &$dstOffset )

Warning

本函数还未编写文档,仅有参数列表。

参数

date

local

rawOffset

dstOffset

返回值

IntlTimeZone::getRawOffset

Get the raw GMT offset (before taking daylight savings time into account

说明

public int IntlTimeZone::getRawOffset ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlTimeZone::getRegion

Get the region code associated with the given system time zone ID

说明

public static string IntlTimeZone::getRegion ( string $zoneId )

Warning

本函数还未编写文档,仅有参数列表。

参数

zoneId

返回值

Return region 或者在失败时返回 FALSE.

IntlTimeZone::getTZDataVersion

Get the timezone data version currently used by ICU

说明

public static string IntlTimeZone::getTZDataVersion ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlTimeZone::getUnknown

Get the "unknown" time zone

说明

public static IntlTimeZone IntlTimeZone::getUnknown ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

Returns IntlTimeZone or NULL on failure.

IntlTimeZone::getWindowsID

Translate a system timezone into a Windows timezone

说明

public static string IntlTimeZone::getWindowsID ( string $timezone )

Translates a system timezone (e.g. "America/Los_Angeles") into a Windows timezone (e.g. "Pacific Standard Time").

Note: This function requires ICU version ≥

Warning

本函数还未编写文档,仅有参数列表。

参数

timezone

返回值

Returns the Windows timezone 或者在失败时返回 FALSE.

参见

  • IntlTimeZone::getIDForWindowsID

IntlTimeZone::hasSameRules

Check if this zone has the same rules and offset as another zone

说明

public bool IntlTimeZone::hasSameRules ( IntlTimeZone $otherTimeZone )

Warning

本函数还未编写文档,仅有参数列表。

参数

otherTimeZone

返回值

IntlTimeZone::toDateTimeZone

Convert to DateTimeZone object

说明

public DateTimeZone IntlTimeZone::toDateTimeZone ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlTimeZone::useDaylightTime

Check if this time zone uses daylight savings time

说明

public bool IntlTimeZone::useDaylightTime ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

简介

Date Formatter is a concrete class that enables locale-dependent formatting/parsing of dates using pattern strings and/or canned patterns.

This class represents the ICU date formatting functionality. It allows users to display dates in a localized format or to parse strings into PHP date values using pattern strings and/or canned patterns.

Class synopsis

IntlDateFormatter

class IntlDateFormatter {

/* 方法 */

public __construct ( string $locale , int $datetype , int $timetype [, mixed $timezone = NULL [, mixed $calendar = NULL [, string $pattern = "" ]]] )

public static IntlDateFormatter create ( string $locale , int $datetype , int $timetype [, mixed $timezone = NULL [, mixed $calendar = NULL [, string $pattern = "" ]]] )

public string format ( mixed $value )

public static string formatObject ( object $object [, mixed $format = NULL [, string $locale = NULL ]] )

public int getCalendar ( void )

public int getDateType ( void )

public int getErrorCode ( void )

public string getErrorMessage ( void )

public string getLocale ([ int $which ] )

public string getPattern ( void )

public int getTimeType ( void )

public string getTimeZoneId ( void )

public IntlCalendar getCalendarObject ( void )

public IntlTimeZone getTimeZone ( void )

public bool isLenient ( void )

public array localtime ( string $value [, int &$position ] )

public int parse ( string $value [, int &$position ] )

public bool setCalendar ( mixed $which )

public bool setLenient ( bool $lenient )

public bool setPattern ( string $pattern )

public bool setTimeZoneId ( string $zone )

public bool setTimeZone ( mixed $zone )

}

参见

预定义常量

These constants are used to specify different formats in the constructor for DateType and TimeType.

IntlDateFormatter::NONE (integer)
Do not include this element

IntlDateFormatter::FULL (integer)
Completely specified style (Tuesday, April 12, 1952 AD or 3:30:42pm PST)

IntlDateFormatter::LONG (integer)
Long style (January 12, 1952 or 3:30:32pm)

IntlDateFormatter::MEDIUM (integer)
Medium style (Jan 12, 1952)

IntlDateFormatter::SHORT (integer)
Most abbreviated style, only essential data (12/13/52 or 3:30pm)

The following int constants are used to specify the calendar. These calendars are all based directly on the Gregorian calendar. Non-Gregorian calendars need to be specified in locale. Examples might include locale="hi@calendar=BUDDHIST".

IntlDateFormatter::TRADITIONAL (integer)
Non-Gregorian Calendar

IntlDateFormatter::GREGORIAN (integer)
Gregorian Calendar

IntlDateFormatter::create

datefmt_create

IntlDateFormatter::__construct

Create a date formatter

说明

面向对象风格

public static IntlDateFormatter IntlDateFormatter::create ( string $locale , int $datetype , int $timetype [, mixed $timezone = NULL [, mixed $calendar = NULL [, string $pattern = "" ]]] )

面向对象风格 (constructor)

public IntlDateFormatter::__construct ( string $locale , int $datetype , int $timetype [, mixed $timezone = NULL [, mixed $calendar = NULL [, string $pattern = "" ]]] )

过程化风格

IntlDateFormatter datefmt_create ( string $locale , int $datetype , int $timetype [, mixed $timezone = NULL [, mixed $calendar = NULL [, string $pattern = "" ]]] )

Create a date formatter.

参数

locale
Locale to use when formatting or parsing or NULL to use the value specified in the ini setting intl.default_locale.

datetype
Date type to use (none, short, medium, long, full). This is one of the IntlDateFormatter constants. It can also be NULL, in which case ICUʼs default date type will be used.

timetype
Time type to use (none, short, medium, long, full). This is one of the IntlDateFormatter constants. It can also be NULL, in which case ICUʼs default time type will be used.

timezone
Time zone ID. The default (and the one used if NULL is given) is the one returned by date_default_timezone_get or, if applicable, that of the IntlCalendar object passed for the calendar parameter. This ID must be a valid identifier on ICUʼs database or an ID representing an explicit offset, such as GMT-05:30.

This can also be an IntlTimeZone or a DateTimeZone object.

calendar
Calendar to use for formatting or parsing. The default value is NULL, which corresponds to IntlDateFormatter::GREGORIAN. This can either be one of the IntlDateFormatter calendar constants or an IntlCalendar. Any IntlCalendar object passed will be clone; it will not be changed by the IntlDateFormatter. This will determine the calendar type used (gregorian, islamic, persian, etc.) and, if NULL is given for the timezone parameter, also the timezone used.

pattern
Optional pattern to use when formatting or parsing. Possible patterns are documented at » http://userguide.icu-project.org/formatparse/datetime.

返回值

The created IntlDateFormatter or FALSE in case of failure.

更新日志

版本 说明
5.5.0/PECL 3.0.0

An IntlCalendar object is allowed for calendar.

Objects of type IntlTimeZone and DateTimeZone are allowed for timezone.

Invalid timezone identifiers (including empty strings) are no longer allowed for timezone.

If NULL is given for timezone, the timezone identifier given by date_default_timezone_get will be used instead of ICUʼs default.

范例

示例 #1 datefmt_create example

<?php
$fmt = datefmt_create( "en_US" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL,
    'America/Los_Angeles', IntlDateFormatter::GREGORIAN  );
echo "First Formatted output is ".datefmt_format( $fmt , 0);
$fmt = datefmt_create( "de-DE" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL,
    'America/Los_Angeles',IntlDateFormatter::GREGORIAN  );
echo "Second Formatted output is ".datefmt_format( $fmt , 0);

$fmt = datefmt_create( "en_US" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL,
     'America/Los_Angeles',IntlDateFormatter::GREGORIAN  ,"MM/dd/yyyy");
echo "First Formatted output with pattern is ".datefmt_format( $fmt , 0);
$fmt = datefmt_create( "de-DE" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL,
     'America/Los_Angeles',IntlDateFormatter::GREGORIAN  ,"MM/dd/yyyy");
echo "Second Formatted output with pattern is ".datefmt_format( $fmt , 0);
?>

示例 #2 OO example

<?php
$fmt = new IntlDateFormatter( "en_US" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL,
    'America/Los_Angeles',IntlDateFormatter::GREGORIAN  );
echo "First Formatted output is ".$fmt->format(0);
$fmt = new IntlDateFormatter( "de-DE" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL, 
    'America/Los_Angeles',IntlDateFormatter::GREGORIAN  );
echo "Second Formatted output is ".$fmt->format(0);

$fmt = new IntlDateFormatter( "en_US" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL, 
     'America/Los_Angeles',IntlDateFormatter::GREGORIAN  ,"MM/dd/yyyy");
echo "First Formatted output with pattern is ".$fmt->format(0);
$fmt = new IntlDateFormatter( "de-DE" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL,
      'America/Los_Angeles',IntlDateFormatter::GREGORIAN , "MM/dd/yyyy");
echo "Second Formatted output with pattern is ".$fmt->format(0);
?>

以上例程会输出:

First Formatted output is Wednesday, December 31, 1969 4:00:00 PM PT
Second Formatted output is Mittwoch, 31. Dezember 1969 16:00 Uhr GMT-08:00
First Formatted output with pattern is 12/31/1969
Second Formatted output with pattern is 12/31/1969

参见

  • datefmt_format
  • datefmt_parse
  • datefmt_get_error_code
  • datefmt_get_error_message

IntlDateFormatter::format

datefmt_format

Format the date/time value as a string

说明

面向对象风格

public string IntlDateFormatter::format ( mixed $value )

过程化风格

string datefmt_format ( IntlDateFormatter $fmt , mixed $value )

Formats the time value as a string.

参数

fmt
The date formatter resource.

value
Value to format. This may be a DateTimeInterface object, an IntlCalendar object, a numeric type representing a (possibly fractional) number of seconds since epoch or an array in the format output by localtime.

If a DateTime or an IntlCalendar object is passed, its timezone is not considered. The object will be formatted using the formaterʼs configured timezone. If one wants to use the timezone of the object to be formatted, IntlDateFormatter::setTimeZone must be called before with the objectʼs timezone. Alternatively, the static function IntlDateFormatter::formatObject may be used instead.

返回值

The formatted string or, if an error occurred, FALSE.

更新日志

版本说明
7.1.5Support for providing general DateTimeInterface objects to the value parameter was added. Formerly, only proper DateTime objects were supported.
5.5.0/PECL 3.0.0Support for providing IntlCalendar objects to the value parameter was added.
5.3.4Support for providing DateTime objects to the value parameter was added.

范例

示例 #1 datefmt_format example

<?php
$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'First Formatted output is ' . datefmt_format($fmt, 0);

$fmt = datefmt_create(
    'de-DE',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'Second Formatted output is ' . datefmt_format($fmt, 0);

$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN,
    'MM/dd/yyyy'
);
echo 'First Formatted output with pattern is ' . datefmt_format($fmt, 0);

$fmt = datefmt_create(
    'de-DE',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN,
    'MM/dd/yyyy'
);
echo "Second Formatted output with pattern is " . datefmt_format($fmt, 0);
?>

示例 #2 OO example

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'First Formatted output is ' . $fmt->format(0);

$fmt = new IntlDateFormatter(
    'de-DE',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'Second Formatted output is ' . $fmt->format(0);

$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN,
    'MM/dd/yyyy'
);
echo 'First Formatted output with pattern is ' . $fmt->format(0);

$fmt = new IntlDateFormatter(
    'de-DE',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN,
    'MM/dd/yyyy'
);
echo 'Second Formatted output with pattern is ' . $fmt->format(0);
?>

以上例程会输出:

First Formatted output is Wednesday, December 31, 1969 4:00:00 PM PT
Second Formatted output is Mittwoch, 31. Dezember 1969 16:00 Uhr GMT-08:00
First Formatted output with pattern is 12/31/1969
Second Formatted output with pattern is 12/31/1969

示例 #3 With IntlCalendar object

<?php
$tz = reset(iterator_to_array(IntlTimeZone::createEnumeration('FR')));
$formatter = IntlDateFormatter::create(
    'fr_FR',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    $tz,
    IntlDateFormatter::GREGORIAN
);

$cal = IntlCalendar::createInstance($tz, '@calendar=islamic-civil');
$cal->set(IntlCalendar::FIELD_MONTH, 8); //9th month, Ramadan
$cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 1); //1st day
$cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY);
$cal->clear(IntlCalendar::FIELD_MINUTE);
$cal->clear(IntlCalendar::FIELD_SECOND);
$cal->clear(IntlCalendar::FIELD_MILLISECOND);

echo "In this islamic year, Ramadan started/will start on:\n\t",
        $formatter->format($cal), "\n";

//Itʼs the formatterʼs timezone that is used:
$formatter->setTimeZone('Asia/Tokyo');
echo "After changing timezone:\n\t",
        $formatter->format($cal), "\n";

以上例程会输出:

In this islamic year, Ramadan started/will start on:
    mardi 9 juillet 2013 19:00:00 heure avancée d’Europe centrale
After changing timezone:
    mercredi 10 juillet 2013 02:00:00 heure normale du Japon

参见

  • datefmt_create
  • datefmt_parse
  • datefmt_get_error_code
  • datefmt_get_error_message
  • datefmt_format_object

IntlDateFormatter::formatObject

datefmt_format_object

Formats an object

说明

面向对象风格

public static string IntlDateFormatter::formatObject ( object $object [, mixed $format = NULL [, string $locale = NULL ]] )

过程化风格

public static string datefmt_format_object ( object $object [, mixed $format = NULL [, string $locale = NULL ]] )

This function allows formatting an IntlCalendar or DateTime object without first explicitly creating a IntlDateFormatter object.

The temporary IntlDateFormatter that will be created will take the timezone from the passed in object. The timezone database bundled with PHP will not be used – ICU's will be used instead. The timezone identifier used in DateTime objects must therefore also exist in ICU's database.

参数

object
An object of type IntlCalendar or DateTime. The timezone information in the object will be used.

format
How to format the date/time. This can either be an array with two elements (first the date style, then the time style, these being one of the constants IntlDateFormatter::NONE, IntlDateFormatter::SHORT, IntlDateFormatter::MEDIUM, IntlDateFormatter::LONG, IntlDateFormatter::FULL), an integer with the value of one of these constants (in which case it will be used both for the time and the date) or a string with the format described in » the ICU documentation. If NULL, the default style will be used.

locale
The locale to use, or NULL to use the default one.

返回值

A string with result 或者在失败时返回 FALSE.

范例

示例 #1 IntlDateFormatter::formatObject examples

<?php
/* default timezone is irrelevant; timezone taken from the object */
ini_set('date.timezone', 'UTC');
/* default locale is taken from this ini setting */
ini_set('intl.default_locale', 'fr_FR');

$cal = IntlCalendar::fromDateTime("2013-06-06 17:05:06 Europe/Dublin");
echo "default:\n\t",
        IntlDateFormatter::formatObject($cal),
        "\n";

echo "long \$format (full):\n\t",
        IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL),
        "\n";

echo "array \$format (none, full):\n\t",
        IntlDateFormatter::formatObject($cal, array(
                IntlDateFormatter::NONE,
                IntlDateFormatter::FULL)),
        "\n";

echo "string \$format (d 'of' MMMM y):\n\t",
        IntlDateFormatter::formatObject($cal, "d 'of' MMMM y", 'en_US'),
        "\n";

echo "with DateTime:\n\t",
        IntlDateFormatter::formatObject(
                new DateTime("2013-09-09 09:09:09 Europe/Madrid"),
                IntlDateFormatter::FULL,
                'es_ES'),
        "\n";

以上例程会输出:

default:
    6 juin 2013 17:05:06
long $format (full):
    jeudi 6 juin 2013 17:05:06 heure d’été irlandaise
array $format (none, full):
    17:05:06 heure d’été irlandaise
string $format (d 'of' MMMM y):
    6 of June 2013
with DateTime:
    lunes, 9 de septiembre de 2013 09:09:09 Hora de verano de Europa central

IntlDateFormatter::getCalendar

datefmt_get_calendar

Get the calendar type used for the IntlDateFormatter

说明

面向对象风格

public int IntlDateFormatter::getCalendar ( void )

过程化风格

int datefmt_get_calendar ( IntlDateFormatter $fmt )

参数

fmt
The formatter resource

返回值

The calendar type being used by the formatter. Either IntlDateFormatter::TRADITIONAL or IntlDateFormatter::GREGORIAN.

范例

示例 #1 datefmt_get_calendar example

<?php
$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'calendar of the formatter is : ' . datefmt_get_calendar($fmt);
datefmt_set_calendar($fmt, IntlDateFormatter::TRADITIONAL);
echo 'Now calendar of the formatter is : ' . datefmt_get_calendar($fmt);
?>

示例 #2 OO example

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'calendar of the formatter is : ' . $fmt->getCalendar();
$fmt->setCalendar(IntlDateFormatter::TRADITIONAL);
echo 'Now calendar of the formatter is : ' . $fmt->getCalendar();

?>

以上例程会输出:

calendar of the formatter is : 1
Now calendar of the formatter is : 0

参见

  • datefmt_get_calendar_object
  • datefmt_set_calendar
  • datefmt_create

IntlDateFormatter::getDateType

datefmt_get_datetype

Get the datetype used for the IntlDateFormatter

说明

面向对象风格

public int IntlDateFormatter::getDateType ( void )

过程化风格

int datefmt_get_datetype ( IntlDateFormatter $fmt )

Returns date type used by the formatter.

参数

fmt
The formatter resource.

返回值

The current date type value of the formatter.

范例

示例 #1 datefmt_get_datetype example

<?php
$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'datetype of the formatter is : ' . datefmt_get_datetype($fmt);
echo 'First Formatted output with datetype is ' . datefmt_format($fmt, 0);

$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::SHORT,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'Now datetype of the formatter is : ' . datefmt_get_datetype($fmt);
echo 'Second Formatted output with datetype is ' . datefmt_format($fmt, 0);

?>

示例 #2 OO example

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'datetype of the formatter is : ' . $fmt->getDateType();
echo 'First Formatted output is ' . $fmt->format(0);
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::SHORT,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'Now datetype of the formatter is : ' . $fmt->getDateType();
echo 'Second Formatted output is ' . $fmt->format(0);

?>

以上例程会输出:

datetype of the formatter is : 0
First Formatted output is Wednesday, December 31, 1969 4:00:00 PM PT
Now datetype of the formatter is : 2
Second Formatted output is 12/31/69 4:00:00 PM PT

参见

  • datefmt_get_timetype
  • datefmt_create

IntlDateFormatter::getErrorCode

datefmt_get_error_code

Get the error code from last operation

说明

面向对象风格

public int IntlDateFormatter::getErrorCode ( void )

过程化风格

int datefmt_get_error_code ( IntlDateFormatter $fmt )

Get the error code from last operation. Returns error code from the last number formatting operation.

参数

fmt
The formatter resource.

返回值

The error code, one of UErrorCode values. Initial value is U_ZERO_ERROR.

范例

示例 #1 datefmt_get_error_code example

<?php
$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
$str = datefmt_format($fmt);
if (!$str) {
    printf(
        "ERROR: %s (%d)\n",
        datefmt_get_error_message($fmt),
        datefmt_get_error_code($fmt)
    );
}
?>

示例 #2 OO example

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
$str = $fmt->format();
if (!$str) {
    printf(
        "ERROR: %s (%d)\n",
        $fmt->getErrorMessage(),
        $fmt->getErrorCode()
    );
}
?>

以上例程会输出:

ERROR: U_ZERO_ERROR (0)

参见

  • datefmt_get_error_message
  • intl_get_error_code
  • intl_is_failure

IntlDateFormatter::getErrorMessage

datefmt_get_error_message

Get the error text from the last operation

说明

面向对象风格

public string IntlDateFormatter::getErrorMessage ( void )

过程化风格

string datefmt_get_error_message ( IntlDateFormatter $fmt )

Get the error text from the last operation.

参数

fmt
The formatter resource.

返回值

Description of the last error.

范例

示例 #1 datefmt_get_error_message example

<?php
$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
$str = datefmt_format($fmt);
if (!$str) {
    printf(
        "ERROR: %s (%d)\n",
        datefmt_get_error_message($fmt),
        datefmt_get_error_code($fmt)
    );
}
?>

示例 #2 OO example

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
$str = $fmt->format();
if(!$str) {
    printf(
        "ERROR: %s (%d)\n",
        $fmt->getErrorMessage(),
        $fmt->getErrorCode()
    );
}

?>

以上例程会输出:

ERROR: U_ZERO_ERROR (0)

参见

  • datefmt_get_error_code
  • intl_get_error_code
  • intl_is_failure

IntlDateFormatter::getLocale

datefmt_get_locale

Get the locale used by formatter

说明

面向对象风格

public string IntlDateFormatter::getLocale ([ int $which ] )

过程化风格

string datefmt_get_locale ( IntlDateFormatter $fmt [, int $which ] )

Get locale used by the formatter.

参数

fmt
The formatter resource

hich
You can choose between valid and actual locale ( Locale::VALID_LOCALE, Locale::ACTUAL_LOCALE, respectively). The default is the actual locale.

返回值

the locale of this formatter or 'false' if error

范例

示例 #1 datefmt_get_locale example

<?php
$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'locale of the formatter is : " . datefmt_get_locale($fmt);
echo 'First Formatted output is " . datefmt_format($fmt, 0);

$fmt = datefmt_create(
    'de-DE',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'locale of the formatter is : ' . datefmt_get_locale($fmt);
echo 'Second Formatted output is ' . datefmt_format($fmt, 0);

?>

示例 #2 OO example

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'locale of the formatter is : ' . $fmt->getLocale();
echo 'First Formatted output is ' . $fmt->format(0);

$fmt = new IntlDateFormatter(
    'de-DE',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'locale of the formatter is : ' . $fmt->getLocale();
echo 'Second Formatted output is ' . $fmt->format(0);

?>

以上例程会输出:

locale of the formatter is : en
First Formatted output is Wednesday, December 31, 1969 4:00:00 PM PT
locale of the formatter is : de
Second Formatted output is Mittwoch, 31. Dezember 1969 16:00 Uhr GMT-08:00

参见

  • datefmt_create

IntlDateFormatter::getPattern

datefmt_get_pattern

Get the pattern used for the IntlDateFormatter

说明

面向对象风格

public string IntlDateFormatter::getPattern ( void )

过程化风格

string datefmt_get_pattern ( IntlDateFormatter $fmt )

Get pattern used by the formatter.

参数

fmt
The formatter resource.

返回值

The pattern string being used to format/parse.

范例

示例 #1 datefmt_get_pattern example

<?php
$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN,
    'MM/dd/yyyy'
);
echo 'pattern of the formatter is : ' . datefmt_get_pattern($fmt);
echo 'First Formatted output with pattern is ' . datefmt_format($fmt, 0);
datefmt_set_pattern($fmt,'yyyymmdd hh:mm:ss z');
echo 'Now pattern of the formatter is : ' . datefmt_get_pattern($fmt);
echo 'Second Formatted output with pattern is ' . datefmt_format($fmt, 0);

?>

示例 #2 OO example

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN,
    'MM/dd/yyyy'
);
echo 'pattern of the formatter is : ' . $fmt->getPattern();
echo 'First Formatted output is ' . $fmt->format(0);
$fmt->setPattern('yyyymmdd hh:mm:ss z');
echo 'Now pattern of the formatter is : ' . $fmt->getPattern();
echo 'Second Formatted output is ' . $fmt->format(0);
?>

以上例程会输出:

pattern of the formatter is : MM/dd/yyyy
First Formatted output is 12/31/1969
Now pattern of the formatter is : yyyymmdd hh:mm:ss z
Second Formatted output is 19690031 04:00:00 PST

参见

  • datefmt_set_pattern
  • datefmt_create

IntlDateFormatter::getTimeType

datefmt_get_timetype

Get the timetype used for the IntlDateFormatter

说明

面向对象风格

public int IntlDateFormatter::getTimeType ( void )

过程化风格

int datefmt_get_timetype ( IntlDateFormatter $fmt )

Return time type used by the formatter.

参数

fmt
The formatter resource.

返回值

The current date type value of the formatter.

范例

示例 #1 datefmt_get_timetype example

<?php
$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'timetype of the formatter is : ' . datefmt_get_timetype($fmt);
echo 'First Formatted output with timetype is ' . datefmt_format($fmt, 0);

$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::SHORT,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'Now timetype of the formatter is : ' . datefmt_get_timetype($fmt);
echo 'Second Formatted output with timetype is ' . datefmt_format($fmt, 0);

?>

示例 #2 OO example

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'timetype of the formatter is : ' . $fmt->getTimeType();
echo 'First Formatted output is ' . $fmt->format(0);

$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::SHORT,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'Now timetype of the formatter is : ' . $fmt->getTimeType();
echo 'Second Formatted output is ' . $fmt->format(0);

?>

以上例程会输出:

timetype of the formatter is : 0
First Formatted output is Wednesday, December 31, 1969 4:00:00 PM PT
Now timetype of the formatter is : 3
Second Formatted output is Wednesday, December 31, 1969 4:00 PM

参见

  • datefmt_get_datetype
  • datefmt_create

IntlDateFormatter::getTimeZoneId

datefmt_get_timezone_id

Get the timezone-id used for the IntlDateFormatter

说明

面向对象风格

public string IntlDateFormatter::getTimeZoneId ( void )

过程化风格

string datefmt_get_timezone_id ( IntlDateFormatter $fmt )

Get the timezone-id used for the IntlDateFormatter.

参数

fmt
The formatter resource.

返回值

ID string for the time zone used by this formatter.

范例

示例 #1 datefmt_get_timezone_id example

<?php
$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'timezone_id of the formatter is : ' . datefmt_get_timezone_id($fmt);
datefmt_set_timezone_id($fmt, 'CN');
echo 'Now timezone_id of the formatter is : ' . datefmt_get_timezone_id($fmt);

?>

示例 #2 OO example

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'timezone_id of the formatter is : ' . $fmt->getTimezoneId();
$fmt->setTimezoneId('CN');
echo 'Now timezone_id of the formatter is : ' . $fmt->getTimezoneId();

?>

以上例程会输出:

timezone_id of the formatter is : America/Los_Angeles
Now timezone_id of the formatter is : CN

参见

  • datefmt_set_timezone_id
  • datefmt_create

IntlDateFormatter::getCalendarObject

datefmt_get_calendar_object

Get copy of formatterʼs calendar object

说明

面向对象风格

public IntlCalendar IntlDateFormatter::getCalendarObject ( void )

过程化风格

IntlCalendar datefmt_get_calendar_object ( void )

Obtain a copy of the calendar object used internally by this formatter. This calendar will have a type (as in gregorian, japanese, buddhist, roc, persian, islamic, etc.) and a timezone that match the type and timezone used by the formatter. The date/time of the object is unspecified.

参数

此函数没有参数。

返回值

A copy of the internal calendar object used by this formatter.

范例

示例 #1 IntlDateFormatter::getCalendarObject example

<?php
$formatter = IntlDateFormatter::create(
    "fr_FR@calendar=islamic", 
    NULL,
    NULL,
    "GMT-01:00",
    IntlDateFormatter::TRADITIONAL
);

$cal = $formatter->getCalendarObject();

var_dump(
    $cal->getType(),
    $cal->getTimeZone(),
    $cal->getLocale(Locale::VALID_LOCALE)
);

以上例程会输出:

string(7) "islamic"
object(IntlTimeZone)#3 (4) {
  ["valid"]=>
  bool(true)
  ["id"]=>
  string(9) "GMT-01:00"
  ["rawOffset"]=>
  int(-3600000)
  ["currentOffset"]=>
  int(-3600000)
}
string(5) "fr_FR"

参见

  • IntlDateFormatter::getCalendar
  • IntlDateFormatter::setCalendar
  • IntlCalendar

IntlDateFormatter::getTimeZone

datefmt_get_timezone

Get formatterʼs timezone

说明

面向对象风格

public IntlTimeZone IntlDateFormatter::getTimeZone ( void )

过程化风格

IntlTimeZone datefmt_get_timezone ( void )

Returns an IntlTimeZone object representing the timezone that will be used by this object to format dates and times. When formatting IntlCalendar and DateTime objects with this IntlDateFormatter, the timezone used will be the one returned by this method, not the one associated with the objects being formatted.

参数

此函数没有参数。

返回值

The associated IntlTimeZone object 或者在失败时返回 FALSE.

范例

示例 #1 IntlDateFormatter::getTimeZone examples

<?php

$madrid = IntlDateFormatter::create(NULL, NULL, NULL, 'Europe/Madrid');
$lisbon = IntlDateFormatter::create(NULL, NULL, NULL, 'Europe/Lisbon');

var_dump($madrid->getTimezone());
echo $madrid->getTimezone()->getDisplayName(
        false, IntlTimeZone::DISPLAY_GENERIC_LOCATION, "en_US"), "\n";
echo $lisbon->getTimeZone()->getId(), "\n";
//The id can also be retrieved with ->getTimezoneId()
echo $lisbon->getTimeZoneId(), "\n";

以上例程会输出:

object(IntlTimeZone)#4 (4) {
  ["valid"]=>
  bool(true)
  ["id"]=>
  string(13) "Europe/Madrid"
  ["rawOffset"]=>
  int(3600000)
  ["currentOffset"]=>
  int(7200000)
}
Spain Time
Europe/Lisbon
Europe/Lisbon

参见

  • IntlDateFormatter::getTimeZoneId
  • IntlDateFormatter::setTimeZone
  • IntlTimeZone

IntlDateFormatter::isLenient

datefmt_is_lenient

Get the lenient used for the IntlDateFormatter

说明

面向对象风格

public bool IntlDateFormatter::isLenient ( void )

过程化风格

bool datefmt_is_lenient ( IntlDateFormatter $fmt )

Check if the parser is strict or lenient in interpreting inputs that do not match the pattern exactly.

参数

fmt
The formatter resource.

返回值

TRUE if parser is lenient, FALSE if parser is strict. By default the parser is lenient.

范例

示例 #1 datefmt_is_lenient example

<?php
$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN,
    'dd/mm/yyyy'
);
echo 'lenient of the formatter is : ';
if ($fmt->isLenient()) {
    echo 'TRUE';
} else {
    echo 'FALSE';
}
datefmt_parse($fmt, '35/13/1971');
echo "\n Trying to do parse('35/13/1971').\nResult is : " . datefmt_parse($fmt, '35/13/1971');
if (intl_get_error_code() != 0) {
    echo "\nError_msg is : " . intl_get_error_message();
    echo "\nError_code is : " . intl_get_error_code();
}
datefmt_set_lenient($fmt,false);
echo 'Now lenient of the formatter is : ';
if ($fmt->isLenient()) {
    echo 'TRUE';
} else {
    echo 'FALSE';
}
datefmt_parse($fmt, '35/13/1971');
echo "\n Trying to do parse('35/13/1971').Result is : " . datefmt_parse($fmt, '35/13/1971');
if (intl_get_error_code() != 0) {
    echo "\nError_msg is : " . intl_get_error_message();
    echo "\nError_code is : " . intl_get_error_code();
}

?>

示例 #2 OO example

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN,
    "dd/mm/yyyy"
);
echo "lenient of the formatter is : ";
if ($fmt->isLenient()) {
    echo 'TRUE';
} else {
    echo 'FALSE';
}
$fmt->parse('35/13/1971');
echo "\n Trying to do parse('35/13/1971').\nResult is : " . $fmt->parse('35/13/1971');
if (intl_get_error_code() != 0){
    echo "\nError_msg is : " . intl_get_error_message();
    echo "\nError_code is : " . intl_get_error_code();
}

$fmt->setLenient(FALSE);
echo 'Now lenient of the formatter is : ';
if ($fmt->isLenient()) {
    echo 'TRUE';
} else {
    echo 'FALSE';
}
$fmt->parse('35/13/1971');
echo "\n Trying to do parse('35/13/1971').\nResult is : " . $fmt->parse('35/13/1971');
if (intl_get_error_code() != 0) {
    echo "\nError_msg is : " . intl_get_error_message();
    echo "\nError_code is : " . intl_get_error_code();
}

?>

以上例程会输出:

lenient of the formatter is : TRUE
Trying to do parse('35/13/1971').
Result is : -2147483
Now lenient of the formatter is : FALSE
Trying to do parse('35/13/1971').
Result is : 
Error_msg is : Date parsing failed: U_PARSE_ERROR 
Error_code is : 9

参见

  • datefmt_set_lenient
  • datefmt_create

IntlDateFormatter::localtime

datefmt_localtime

Parse string to a field-based time value

说明

面向对象风格

public array IntlDateFormatter::localtime ( string $value [, int &$position ] )

过程化风格

array datefmt_localtime ( IntlDateFormatter $fmt , string $value [, int &$position ] )

Converts string $value to a field-based time value ( an array of various fields), starting at $parse_pos and consuming as much of the input value as possible.

参数

fmt
The formatter resource

value
string to convert to a time

position
Position at which to start the parsing in $value (zero-based). If no error occurs before $value is consumed, $parse_pos will contain -1 otherwise it will contain the position at which parsing ended . If $parse_pos > strlen($value), the parse fails immediately.

返回值

Localtime compatible array of integers : contains 24 hour clock value in tm_hour field

范例

示例 #1 datefmt_localtime example

<?php

$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
$arr = datefmt_localtime($fmt, 'Wednesday, December 31, 1969 4:00:00 PM PT', 0);
echo 'First parsed output is ';
if ($arr) {
    foreach ($arr as $key => $value) {
        echo "$key : $value , ";
    }
}

?>

示例 #2 OO example

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
$arr = $fmt->localtime('Wednesday, December 31, 1969 4:00:00 PM PT', 0);
echo 'First parsed output is ';
if ($arr) {
    foreach ($arr as $key => $value) {
        echo "$key : $value , ";
    }
}

?>

以上例程会输出:

First parsed output is tm_sec : 0 , tm_min : 0 , tm_hour : 16 , tm_year : 1969 , 
tm_mday : 31 , tm_wday : 4 , tm_yday : 365 , tm_mon : 11 , tm_isdst : 0 , 

参见

  • datefmt_create
  • datefmt_format
  • datefmt_parse
  • datefmt_get_error_code
  • datefmt_get_error_message

IntlDateFormatter::parse

datefmt_parse

Parse string to a timestamp value

说明

面向对象风格

public int IntlDateFormatter::parse ( string $value [, int &$position ] )

过程化风格

int datefmt_parse ( IntlDateFormatter $fmt , string $value [, int &$position ] )

Converts string $value to an incremental time value, starting at $parse_pos and consuming as much of the input value as possible.

参数

fmt
The formatter resource

value
string to convert to a time

position
Position at which to start the parsing in $value (zero-based). If no error occurs before $value is consumed, $parse_pos will contain -1 otherwise it will contain the position at which parsing ended (and the error occurred). This variable will contain the end position if the parse fails. If $parse_pos > strlen($value), the parse fails immediately.

返回值

timestamp parsed value, or FALSE if value can't be parsed.

范例

示例 #1 OO example

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'First parsed output is ' . $fmt->parse('Wednesday, December 20, 1989 4:00:00 PM PT');
$fmt = new IntlDateFormatter(
    'de-DE',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
?>

示例 #2 datefmt_parse example

<?php
$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'First parsed output is ' . datefmt_parse($fmt, 'Wednesday, December 20, 1989 4:00:00 PM PT');
$fmt = datefmt_create(
    'de-DE',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'Second parsed output is ' . datefmt_parse($fmt, 'Mittwoch, 20. Dezember 1989 16:00 Uhr GMT-08:00');
?

以上例程会输出:

First parsed output is 630201600
Second parsed output is 630201600

参见

  • datefmt_create
  • datefmt_format
  • datefmt_localtime
  • datefmt_get_error_code
  • datefmt_get_error_message

IntlDateFormatter::setCalendar

datefmt_set_calendar

Sets the calendar type used by the formatter

说明

面向对象风格

public bool IntlDateFormatter::setCalendar ( mixed $which )

过程化风格

bool datefmt_set_calendar ( IntlDateFormatter $fmt , mixed $which )

Sets the calendar or calendar type used by the formatter.

参数

fmt
The formatter resource.

which
This can either be: the calendar type to use (default is IntlDateFormatter::GREGORIAN, which is also used if NULL is specified) or an IntlCalendar object.

Any IntlCalendar object passed in will be cloned; no modifications will be made to the argument object.

The timezone of the formatter will only be kept if an IntlCalendar object is not passed, otherwise the new timezone will be that of the passed object.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

更新日志

版本说明
5.5.0/PECL 3.0.0It became possible to pass an IntlCalendar object.

范例

示例 #1 datefmt_set_calendar example

<?php
$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'calendar of the formatter is : ' . datefmt_get_calendar($fmt);
datefmt_set_calendar($fmt, IntlDateFormatter::TRADITIONAL);
echo 'Now calendar of the formatter is : ' . datefmt_get_calendar($fmt);
?>

示例 #2 OO example

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN  
);
echo 'calendar of the formatter is : ' . $fmt->getCalendar();
$fmt->setCalendar(IntlDateFormatter::TRADITIONAL);
echo 'Now calendar of the formatter is : ' . $fmt->getCalendar();
?>

以上例程会输出:

calendar of the formatter is : 1
Now calendar of the formatter is : 0

示例 #3 Example with IntlCalendar argument

<?php
$time = strtotime("2013-03-03 00:00:00 UTC");
$formatter = IntlDateFormatter::create("en_US", NULL, NULL, "Europe/Amsterdam");

echo "before: ", $formatter->format($time), "\n";

/* note that the calendar's locale is not used! */
$formatter->setCalendar(IntlCalendar::createInstance(
               "America/New_York", "pt_PT@calendar=islamic"));

echo "after:  ", $formatter->format($time), "\n";

以上例程会输出:

before: Sunday, March 3, 2013 at 1:00:00 AM Central European Standard Time
after:  Saturday, Rabiʻ II 20, 1434 at 7:00:00 PM Eastern Standard Time

参见

  • datefmt_get_calendar
  • datefmt_get_calendar_object
  • datefmt_create

IntlDateFormatter::setLenient

datefmt_set_lenient

Set the leniency of the parser

说明

面向对象风格

public bool IntlDateFormatter::setLenient ( bool $lenient )

过程化风格

bool datefmt_set_lenient ( IntlDateFormatter $fmt , bool $lenient )

Define if the parser is strict or lenient in interpreting inputs that do not match the pattern exactly. Enabling lenient parsing allows the parser to accept otherwise flawed date or time patterns, parsing as much as possible to obtain a value. Extra space, unrecognized tokens, or invalid values ("February 30th") are not accepted.

参数

fmt
The formatter resource

lenient
Sets whether the parser is lenient or not, default is TRUE (lenient).

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 datefmt_set_lenient example

<?php
$fmt = datefmt_create(
    'en_US', 
    IntlDateFormatter::FULL, 
    IntlDateFormatter::FULL, 
    'America/Los_Angeles', 
    IntlDateFormatter::GREGORIAN, 
    'dd/MM/yyyy'
);
echo 'lenient of the formatter is : ';
if ($fmt->isLenient()) {
    echo 'TRUE';
} else {
    echo 'FALSE';
}
datefmt_parse($fmt, '35/13/1971');
echo "\n Trying to do parse('35/13/1971').\nResult is : " . datefmt_parse($fmt, '35/13/1971');
if (intl_get_error_code() != 0) {
    echo "\nError_msg is : " . intl_get_error_message();
    echo "\nError_code is : " . intl_get_error_code();
}
datefmt_set_lenient($fmt, false);
echo "\nNow lenient of the formatter is : ";
if ($fmt->isLenient()) {
    echo 'TRUE';
} else {
    echo 'FALSE';
}
datefmt_parse($fmt, '35/13/1971');
echo "\nTrying to do parse('35/13/1971').\nResult is : " . datefmt_parse($fmt, '35/13/1971');
if (intl_get_error_code() != 0) {
    echo "\nError_msg is : ".intl_get_error_message();
    echo "\nError_code is : ".intl_get_error_code();
}

?>

示例 #2 OO example

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN,
    'dd/MM/yyyy'
);
echo 'lenient of the formatter is : ';
if ($fmt->isLenient()) {
    echo 'TRUE';
} else {
    echo 'FALSE';
}
$fmt->parse('35/13/1971');
echo "\n Trying to do parse('35/13/1971').\nResult is : " . $fmt->parse('35/13/1971');
if (intl_get_error_code() != 0) {
    echo "\nError_msg is : " . intl_get_error_message();
    echo "\nError_code is : " . intl_get_error_code();
}

$fmt->setLenient(FALSE);
echo "\nNow lenient of the formatter is : ";
if ($fmt->isLenient()) {
    echo 'TRUE';
} else {
    echo 'FALSE';
}
$fmt->parse('35/13/1971');
echo "\n Trying to do parse('35/13/1971').\nResult is : " . $fmt->parse('35/13/1971');
if (intl_get_error_code() != 0) {
    echo "\nError_msg is : " . intl_get_error_message();
    echo "\nError_code is : " . intl_get_error_code();
}

?>

以上例程会输出:

lenient of the formatter is : TRUE
Trying to do parse('35/13/1971').
Result is : 66038400
Now lenient of the formatter is : FALSE
Trying to do parse('35/13/1971').
Result is : 
Error_msg is : Date parsing failed: U_PARSE_ERROR
Error_code is : 9

参见

  • datefmt_is_lenient
  • datefmt_create

IntlDateFormatter::setPattern

datefmt_set_pattern

Set the pattern used for the IntlDateFormatter

说明

面向对象风格

public bool IntlDateFormatter::setPattern ( string $pattern )

过程化风格

bool datefmt_set_pattern ( IntlDateFormatter $fmt , string $pattern )

Set the pattern used for the IntlDateFormatter.

参数

fmt
The formatter resource.

pattern
New pattern string to use. Possible patterns are documented at » http://userguide.icu-project.org/formatparse/datetime.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE。 Bad formatstrings are usually the cause of the failure.

范例

示例 #1 datefmt_set_pattern example

<?php
$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN,
    'MM/dd/yyyy'
);
echo 'pattern of the formatter is : ' . datefmt_get_pattern($fmt);
echo 'First Formatted output with pattern is ' . datefmt_format($fmt, 0);
datefmt_set_pattern($fmt, 'yyyymmdd hh:mm:ss z');
echo 'Now pattern of the formatter is : ' . datefmt_get_pattern($fmt);
echo 'Second Formatted output with pattern is ' . datefmt_format($fmt, 0);

?>

示例 #2 OO example

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN,
    'MM/dd/yyyy'
);
echo 'pattern of the formatter is : ' . $fmt->getPattern();
echo 'First Formatted output is ' . $fmt->format(0);
$fmt->setPattern('yyyymmdd hh:mm:ss z');
echo 'Now pattern of the formatter is : ' . $fmt->getPattern();
echo 'Second Formatted output is ' . $fmt->format(0);

?>

以上例程会输出:

pattern of the formatter is : MM/dd/yyyy
First Formatted output with pattern is 12/31/1969
Now pattern of the formatter is : yyyymmdd hh:mm:ss z
Second Formatted output with pattern is 19690031 04:00:00 PST

参见

  • datefmt_get_pattern
  • datefmt_create

IntlDateFormatter::setTimeZoneId

datefmt_set_timezone_id

Sets the time zone to use

Warning

This function was DEPRECATED in PHP 5.5.0, and REMOVED in PHP 7.0.0.

Alternatives to this function include:

  • IntlDateFormatter::setTimeZone

说明

面向对象风格

public bool IntlDateFormatter::setTimeZoneId ( string $zone )

过程化风格

bool datefmt_set_timezone_id ( IntlDateFormatter $fmt , string $zone )

Sets the time zone to use.

参数

fmt
The formatter resource.

zone
The time zone ID string of the time zone to use. If NULL or the empty string, the default time zone for the runtime is used.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

更新日志

版本说明
7.0.0This function has been removed.
5.5.0This function has been deprecated.

范例

示例 #1 datefmt_set_timezone_id example

<?php
$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'timezone_id of the formatter is : ' . datefmt_get_timezone_id($fmt);
datefmt_set_timezone_id($fmt, 'CN');
echo 'Now timezone_id of the formatter is : ' . datefmt_get_timezone_id($fmt);
?>

示例 #2 OO example

<?php
$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);
echo 'timezone_id of the formatter is : ' . $fmt->getTimezoneId();
$fmt->setTimezoneId('CN');
echo 'Now timezone_id of the formatter is : ' . $fmt->getTimezoneId();

?>

以上例程会输出:

timezone_id of the formatter is : America/Los_Angeles
Now timezone_id of the formatter is : CN

参见

  • datefmt_get_timezone_id
  • datefmt_create

IntlDateFormatter::setTimeZone

datefmt_set_timezone

Sets formatterʼs timezone

说明

面向对象风格

public bool IntlDateFormatter::setTimeZone ( mixed $zone )

过程化风格

bool datefmt_set_timezone ( IntlDateFormatter $fmt , mixed $zone )

Sets the timezone used for the IntlDateFormatter. object.

参数

fmt
The formatter resource.

zone
The timezone to use for this formatter. This can be specified in the following forms:

  • NULL, in which case the default timezone will be used, as specified in the ini setting date.timezone or through the function date_default_timezone_set and as returned by date_default_timezone_get.

  • An IntlTimeZone, which will be used directly.

  • A DateTimeZone. Its identifier will be extracted and an ICU timezone object will be created; the timezone will be backed by ICUʼs database, not PHPʼs.

  • A string, which should be a valid ICU timezone identifier. See IntlTimeZone::createTimeZoneIDEnumeration. Raw offsets such as "GMT+08:30" are also accepted.

返回值

Returns TRUE on success and FALSE on failure.

范例

示例 #1 IntlDateFormatter::setTimeZone examples

<?php
ini_set('date.timezone', 'Europe/Amsterdam');

$formatter = IntlDateFormatter::create(NULL, NULL, NULL, "UTC");

$formatter->setTimeZone(NULL);
echo "NULL\n    ", $formatter->getTimeZone()->getId(), "\n";

$formatter->setTimeZone(IntlTimeZone::createTimeZone('Europe/Lisbon'));
echo "IntlTimeZone\n    ", $formatter->getTimeZone()->getId(), "\n";

$formatter->setTimeZone(new DateTimeZone('Europe/Paris'));
echo "DateTimeZone\n    ", $formatter->getTimeZone()->getId(), "\n";

$formatter->setTimeZone('Europe/Rome');
echo "String\n    ", $formatter->getTimeZone()->getId(), "\n";

$formatter->setTimeZone('GMT+00:30');
print_r($formatter->getTimeZone());

以上例程会输出:

NULL
    Europe/Amsterdam
IntlTimeZone
    Europe/Lisbon
DateTimeZone
    Europe/Paris
String
    Europe/Rome
IntlTimeZone Object
(
    [valid] => 1
    [id] => GMT+00:30
    [rawOffset] => 1800000
    [currentOffset] => 1800000
)

参见

  • IntlDateFormatter::getTimeZone

简介

Localized software products often require sets of data that are to be customized depending on current locale, e.g.: messages, labels, formatting patterns. ICU resource mechanism allows to define sets of resources that the application can load on locale basis, while accessing them in unified locale-independent fashion.

This class implements access to ICU resource data files. These files are binary data arrays which ICU uses to store the localized data.

ICU resource bundle can hold simple resources and complex resources. Complex resources are containers which can be either integer-indexed or string-indexed (just like PHP arrays). Simple resources can be of the following types: string, integer, binary data field or integer array.

ResourceBundle supports direct access to the data through array access pattern and iteration via foreach, as well as access via class methods. The result will be PHP value for simple resources and ResourceBundle object for complex ones. All resources are read-only.

类摘要

ResourceBundle

class ResourceBundle {

/* Methods */

public __construct ( string $locale , string $bundlename [, bool $fallback ] )

public int count ( void )

public static ResourceBundle create ( string $locale , string $bundlename [, bool $fallback ] )

public int getErrorCode ( void )

public string getErrorMessage ( void )

public mixed get ( string|int $index [, bool $fallback = TRUE ] )

public array getLocales ( string $bundlename )

}

参见

ResourceBundle::count

resourcebundle_count

Get number of elements in the bundle

说明

面向对象风格

public int ResourceBundle::count ( void )

过程化风格

int resourcebundle_count ( ResourceBundle $r )

Get the number of elements in the bundle.

参数

r
ResourceBundle object.

返回值

Returns number of elements in the bundle.

范例

示例 #1 resourcebundle_count example

<?php
$r = resourcebundle_create( 'es', "/usr/share/data/myapp");
echo resourcebundle_count($r);
?>

示例 #2 OO example

<?php
$r = new ResourceBundle( 'es', "/usr/share/data/myapp");
echo $r->count();
?>

以上例程会输出:

42

参见

  • resourcebundle_get

ResourceBundle::create

resourcebundle_create

ResourceBundle::__construct

Create a resource bundle

说明

面向对象风格 (method)

public static ResourceBundle ResourceBundle::create ( string $locale , string $bundlename [, bool $fallback ] )

过程化风格

ResourceBundle resourcebundle_create ( string $locale , string $bundlename [, bool $fallback ] )

面向对象风格 (constructor):

public ResourceBundle::__construct ( string $locale , string $bundlename [, bool $fallback ] )

Creates a resource bundle.

参数

locale
Locale for which the resources should be loaded (locale name, e.g. en_CA).

bundlename
The directory where the data is stored or the name of the .dat file.

fallback
Whether locale should match exactly or fallback to parent locale is allowed.

返回值

Returns ResourceBundle object or NULL on error.

范例

示例 #1 resourcebundle_create example

<?php
$r = resourcebundle_create( 'es', "/usr/share/data/myapp");
echo $r['teststring'];
?>

示例 #2 ResourceBundle::create example

<?php
$r = ResourceBundle::create( 'es', "/usr/share/data/myapp");
echo $r['teststring'];
?>

以上例程会输出:

¡Hola, mundo!

参见

  • resourcebundle_get

ResourceBundle::getErrorCode

resourcebundle_get_error_code

Get bundle's last error code

说明

面向对象风格

public int ResourceBundle::getErrorCode ( void )

过程化风格

int resourcebundle_get_error_code ( ResourceBundle $r )

Get error code from the last function performed by the bundle object.

参数

r
ResourceBundle object.

返回值

Returns error code from last bundle object call.

范例

示例 #1 resourcebundle_get_error_code example

<?php
$r = resourcebundle_create( 'es', "/usr/share/data/myapp");
echo $r['somestring'];
if(intl_is_failure(resourcebundle_get_error_code($r))) {
    report_error("Bundle error");
}
?>

示例 #2 OO example

<?php
$r = new ResourceBundle( 'es', "/usr/share/data/myapp");
echo $r['somestring'];
if(intl_is_failure(ResourceBundle::getErrorCode($r))) {
    report_error("Bundle error");
}
?>

参见

  • resourcebundle_get_error_message
  • intl_get_error_code
  • intl_is_failure

ResourceBundle::getErrorMessage

resourcebundle_get_error_message

Get bundle's last error message

说明

面向对象风格

public string ResourceBundle::getErrorMessage ( void )

过程化风格

string resourcebundle_get_error_message ( ResourceBundle $r )

Get error message from the last function performed by the bundle object.

参数

r
ResourceBundle object.

返回值

Returns error message from last bundle object's call.

范例

示例 #1 resourcebundle_get_error_message example

<?php
$r = resourcebundle_create( 'es', "/usr/share/data/myapp");
echo $r['somestring'];
if(intl_is_failure(resourcebundle_get_error_code($r))) {
    report_error("Bundle error: ".resourcebundle_get_error_message($r));
}
?>

示例 #2 OO example

<?php
$r = new ResourceBundle( 'es', "/usr/share/data/myapp");
echo $r['somestring'];
if(intl_is_failure(ResourceBundle::getErrorCode($r))) {
    report_error("Bundle error: ".ResourceBundle::getErrorMessage($r));
}
?>

参见

  • resourcebundle_get_error_code
  • intl_get_error_code
  • intl_is_failure

ResourceBundle::get

resourcebundle_get

Get data from the bundle

说明

面向对象风格

public mixed ResourceBundle::get ( string|int $index [, bool $fallback = TRUE ] )

过程化风格

mixed resourcebundle_get ( ResourceBundle $r , string|int $index [, bool $fallback = TRUE ] )

Get the data from the bundle by index or string key.

参数

r
ResourceBundle object.

index
Data index, must be string or integer.

fallback
Whether locale should match exactly or fallback to parent locale is allowed.

返回值

Returns the data located at the index or NULL on error. Strings, integers and binary data strings are returned as corresponding PHP types, integer array is returned as PHP array. Complex types are returned as ResourceBundle object.

范例

示例 #1 resourcebundle_get example

<?php
$r = resourcebundle_create( 'es', "/usr/share/data/myapp");
echo resourcebundle_get($r, 'somestring');
?>

示例 #2 OO example

<?php
$r = new ResourceBundle( 'es', "/usr/share/data/myapp");
echo $r->get('somestring');
?>

以上例程会输出:

?Hola, mundo!

参见

  • resourcebundle_count

ResourceBundle::getLocales

resourcebundle_locales

Get supported locales

说明

面向对象风格

public array ResourceBundle::getLocales ( string $bundlename )

过程化风格

array resourcebundle_locales ( string $bundlename )

Get available locales from ResourceBundle name.

参数

bundlename
Path of ResourceBundle for which to get available locales, or empty string for default locales list.

返回值

Returns the list of locales supported by the bundle.

范例

示例 #1 resourcebundle_locales example

<?php
$bundle = "/user/share/data/myapp";
echo join(PHP_EOL, resourcebundle_locales($bundle));
?>

以上例程的输出类似于:

es
root

示例 #2 OO example

<?php
$bundle = "/usr/share/data/myapp";
$r = new ResourceBundle( 'es', $bundle);
echo join("\n", $r->getLocales($bundle));
?>

以上例程的输出类似于:

es
root

参见

  • resourcebundle_get

简介

This class is provided because Unicode contains large number of characters and incorporates the varied writing systems of the world and their incorrect usage can expose programs or systems to possible security attacks using characters similarity.

Provided methods allow to check whether an individual string is likely an attempt at confusing the reader (spoof detection), such as "pаypаl" spelled with Cyrillic 'а' characters.

类摘要

Spoofchecker

class Spoofchecker {

/* Constants */

const number Spoofchecker::ASCII = 0x10000000 ;

const number Spoofchecker::HIGHLY_RESTRICTIVE = 0x30000000 ;

const number Spoofchecker::MODERATELY_RESTRICTIVE = 0x40000000 ;

const number Spoofchecker::MINIMALLY_RESTRICTIVE = 0x50000000 ;

const number Spoofchecker::UNRESTRICTIVE = 0x60000000 ;

const number Spoofchecker::SINGLE_SCRIPT_RESTRICTIVE = 0x20000000 ;

const integer Spoofchecker::SINGLE_SCRIPT_CONFUSABLE = 1 ;

const integer Spoofchecker::MIXED_SCRIPT_CONFUSABLE = 2 ;

const integer Spoofchecker::WHOLE_SCRIPT_CONFUSABLE = 4 ;

const integer Spoofchecker::ANY_CASE = 8 ;

const integer Spoofchecker::SINGLE_SCRIPT = 16 ;

const integer Spoofchecker::INVISIBLE = 32 ;

const integer Spoofchecker::CHAR_LIMIT = 64 ;

/* 方法 */

public bool areConfusable ( string $str1 , string $str2 [, string &$error ] )

public __construct ( void )

public bool isSuspicious ( string $text [, string &$error ] )

public void setAllowedLocales ( string $locale_list )

public void setChecks ( int $checks )

}

预定义常量

Spoofchecker::ASCII

Spoofchecker::HIGHLY_RESTRICTIVE

Spoofchecker::MODERATELY_RESTRICTIVE

Spoofchecker::MINIMALLY_RESTRICTIVE

Spoofchecker::UNRESTRICTIVE

Spoofchecker::SINGLE_SCRIPT_RESTRICTIVE

Spoofchecker::SINGLE_SCRIPT_CONFUSABLE

Spoofchecker::MIXED_SCRIPT_CONFUSABLE

Spoofchecker::WHOLE_SCRIPT_CONFUSABLE

Spoofchecker::ANY_CASE

Spoofchecker::SINGLE_SCRIPT

Spoofchecker::INVISIBLE

Spoofchecker::CHAR_LIMIT

更新日志

版本说明
7.3.0Class constants used by Spoofchecker::setRestrictionLevel such as Spoofchecker::ASCII, Spoofchecker::HIGHLY_RESTRICTIVE, Spoofchecker::MODERATELY_RESTRICTIVE, Spoofchecker::MINIMALLY_RESTRICTIVE, Spoofchecker::UNRESTRICTIVE, Spoofchecker::SINGLE_SCRIPT_RESTRICTIVE has been added.

Spoofchecker::areConfusable

Checks if given strings can be confused

说明

public bool Spoofchecker::areConfusable ( string $str1 , string $str2 [, string &$error ] )

Checks whether two given strings can easily be mistaken.

参数

str1
First string to check.

str2
Second string to check.

error
This variable is set by-reference to string containing an error, if there were any.

返回值

Returns TRUE if two given strings can be confused, FALSE otherwise.

范例

示例 #1 Spoofchecker::areConfusable example

<?php
$checker = new Spoofchecker();

$checker->areConfusable('google.com', 'goog1e.com'); // true
// Lower l can be confused with digit one

$checker->areConfusable('google.com', 'g00g1e.com'); // false
// Zero (0) cannot be easily confused with "o" letter

Spoofchecker::__construct

Constructor

说明

public Spoofchecker::__construct ( void )

Creates new instance of Spoofchecker.

参数

此函数没有参数。

返回值

Returns Spoofchecker instance.

Spoofchecker::isSuspicious

Checks if a given text contains any suspicious characters

说明

public bool Spoofchecker::isSuspicious ( string $text [, string &$error ] )

Checks if given string contains any suspicious characters like letters which are almost identical visually, but are Unicode characters from different sets.

参数

text
String to test.

error
This variable is set by-reference to string containing an error, if there were any.

返回值

Returns TRUE if there are suspicious characters, FALSE otherwise.

范例

示例 #1 Spoofchecker::isSuspicious example

<?php
$checker = new Spoofchecker();

$checker->isSuspicious('google.com'); // FALSE: only ASCII characters

$checker->isSuspicious('Рaypal.com'); // TRUE
// The first letter is from Cyrylic, not a regular latin "P"

Spoofchecker::setAllowedLocales

Locales to use when running checks

说明

public void Spoofchecker::setAllowedLocales ( string $locale_list )

Warning

本函数还未编写文档,仅有参数列表。

参数

locale_list

返回值

Spoofchecker::setChecks

Set the checks to run

说明

public void Spoofchecker::setChecks ( int $checks )

Warning

本函数还未编写文档,仅有参数列表。

参数

checks

返回值

简介

Transliterator provides transliteration of strings.

类摘要

Transliterator

class Transliterator {

/* 常量 */

const integer Transliterator::FORWARD = 0 ;

const integer Transliterator::REVERSE = 1 ;

/* 属性 */

public $id ;

/* 方法 */

__construct ( void )

public static Transliterator create ( string $id [, int $direction ] )

public static Transliterator createFromRules ( string $rules [, string $direction ] )

public Transliterator createInverse ( void )

public int getErrorCode ( void )

public string getErrorMessage ( void )

public static array listIDs ( void )

public string transliterate ( string $subject [, int $start [, int $end ]] )

}

属性

id

预定义常量

Transliterator::FORWARD

Transliterator::REVERSE

Transliterator::__construct

Private constructor to deny instantiation

说明

Transliterator::__construct ( void )

This method should not be called. Its only purpose is to deny instantiation with the new operator.

Use the factory methods Transliterator::create or Transliterator::createFromRules instead.

参数

此函数没有参数。

返回值

This method should not be executed. If it is (e.g. through reflection), then its return value is unspecified.

参见

  • Transliterator::create
  • Transliterator::createFromRules

Transliterator::create

transliterator_create

Create a transliterator

说明

面向对象风格

public static Transliterator Transliterator::create ( string $id [, int $direction ] )

过程化风格

Transliterator transliterator_create ( string $id [, int $direction ] )

Opens a Transliterator by id.

Warning

本函数还未编写文档,仅有参数列表。

参数

id
The id.

direction
The direction, defaults to >Transliterator::FORWARD. May also be set to Transliterator::REVERSE.

返回值

Returns a Transliterator object on success, or NULL on failure.

参见

  • Transliterator::getErrorMessage
  • Transliterator::__construct

Transliterator::createFromRules

transliterator_create_from_rules

Create transliterator from rules

说明

面向对象风格

public static Transliterator Transliterator::createFromRules ( string $rules [, string $direction ] )

过程化风格

Transliterator transliterator_create_from_rules ( string $id [, int $direction ] )

Creates a Transliterator from rules.

Warning

本函数还未编写文档,仅有参数列表。

参数

rules
The rules.

direction
The direction, defaults to >Transliterator::FORWARD. May also be set to Transliterator::REVERSE.

返回值

Returns a Transliterator object on success, or NULL on failure.

参见

  • Transliterator::getErrorMessage
  • Transliterator::create

Transliterator::createInverse

transliterator_create_inverse

Create an inverse transliterator

说明

面向对象风格

public Transliterator Transliterator::createInverse ( void )

过程化风格

Transliterator transliterator_create_inverse ( void )

Opens the inverse transliterator.

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

Returns a Transliterator object on success, or NULL on failure

参见

  • Transliterator::getErrorMessage
  • Transliterator::create

Transliterator::getErrorCode

transliterator_get_error_code

Get last error code

说明

面向对象风格

public int Transliterator::getErrorCode ( void )

过程化风格

int transliterator_get_error_code ( Transliterator $trans )

Gets the last error code for this transliterator.

Warning

本函数还未编写文档,仅有参数列表。

参数

trans

返回值

The error code on success, or FALSE if none exists, or on failure.

参见

  • Transliterator::getErrorMessage
  • Transliterator::listIDs

Transliterator::getErrorMessage

transliterator_get_error_message

Get last error message

说明

面向对象风格

public string Transliterator::getErrorMessage ( void )

过程化风格

string transliterator_get_error_message ( Transliterator $trans )

Gets the last error message for this transliterator.

Warning

本函数还未编写文档,仅有参数列表。

参数

trans

返回值

The error message on success, or FALSE if none exists, or on failure.

参见

  • Transliterator::getErrorCode
  • Transliterator::listIDs

Transliterator::listIDs

transliterator_list_ids

Get transliterator IDs

说明

面向对象风格

public static array Transliterator::listIDs ( void )

过程化风格

array transliterator_list_ids ( void )

Returns an array with the registered transliterator IDs.

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

An array of registered transliterator IDs on success, 或者在失败时返回 FALSE.

参见

  • Transliterator::getErrorMessage
  • Transliterator::transliterate

Transliterator::transliterate

transliterator_transliterate

Transliterate a string

说明

面向对象风格

public string Transliterator::transliterate ( string $subject [, int $start [, int $end ]] )

过程化风格

transliterator_transliterate ( mixed $transliterator , string $subject [, int $start [, int $end ]] )

Transforms a string or part thereof using an ICU transliterator.

参数

transliterator
In the procedural version, either a Transliterator or a string from which a Transliterator can be built.

subject
The string to be transformed.

start
The start index (in UTF-16 code units) from which the string will start to be transformed, inclusive. Indexing starts at 0. The text before will be left as is.

end
The end index (in UTF-16 code units) until which the string will be transformed, exclusive. Indexing starts at 0. The text after will be left as is.

返回值

The transformed string on success, 或者在失败时返回 FALSE.

范例

示例 #1 Converting escaped UTF-16 code units

<?php
$s = "\u304A\u65E9\u3046\u3054\u3056\u3044\u307E\u3059";
echo transliterator_transliterate("Hex-Any/Java", $s), "\n";

//now the reverse operation with a supplementary character
$supplChar = html_entity_decode('&#x1D11E;');
echo mb_strlen($supplChar, "UTF-8"), "\n";
$encSupplChar = transliterator_transliterate("Any-Hex/Java", $supplChar);
//echoes two encoded UTF-16 code units
echo $encSupplChar, "\n";
//and back
echo transliterator_transliterate("Hex-Any/Java", $encSupplChar), "\n";
?>

以上例程的输出类似于:

お早うございます
1
\uD834\uDD1E
𝄞

参见

  • Transliterator::getErrorMessage
  • Transliterator::__construct

简介

A “break iterator” is an ICU object that exposes methods for locating boundaries in text (e.g. word or sentence boundaries). The PHP IntlBreakIterator serves as the base class for all types of ICU break iterators. Where extra functionality is available, the intl extension may expose the ICU break iterator with suitable subclasses, such as IntlRuleBasedBreakIterator or IntlCodePointBreakIterator.

This class implements Traversable. Traversing an IntlBreakIterator yields non-negative integer values representing the successive locations of the text boundaries, expressed as UTF-8 code units (byte) counts, taken from the beginning of the text (which has the location 0). The keys yielded by the iterator simply form the sequence of natural numbers {0, 1, 2, …}.

类摘要

IntlBreakIterator

class IntlBreakIterator implements Traversable {

/* 常量 */

const integer IntlBreakIterator::DONE = -1 ;

const integer IntlBreakIterator::WORD_NONE = 0 ;

const integer IntlBreakIterator::WORD_NONE_LIMIT = 100 ;

const integer IntlBreakIterator::WORD_NUMBER = 100 ;

const integer IntlBreakIterator::WORD_NUMBER_LIMIT = 200 ;

const integer IntlBreakIterator::WORD_LETTER = 200 ;

const integer IntlBreakIterator::WORD_LETTER_LIMIT = 300 ;

const integer IntlBreakIterator::WORD_KANA = 300 ;

const integer IntlBreakIterator::WORD_KANA_LIMIT = 400 ;

const integer IntlBreakIterator::WORD_IDEO = 400 ;

const integer IntlBreakIterator::WORD_IDEO_LIMIT = 500 ;

const integer IntlBreakIterator::LINE_SOFT = 0 ;

const integer IntlBreakIterator::LINE_SOFT_LIMIT = 100 ;

const integer IntlBreakIterator::LINE_HARD = 100 ;

const integer IntlBreakIterator::LINE_HARD_LIMIT = 200 ;

const integer IntlBreakIterator::SENTENCE_TERM = 0 ;

const integer IntlBreakIterator::SENTENCE_TERM_LIMIT = 100 ;

const integer IntlBreakIterator::SENTENCE_SEP = 100 ;

const integer IntlBreakIterator::SENTENCE_SEP_LIMIT = 200 ;

/* 方法 */

private __construct ( void )

public static IntlBreakIterator createCharacterInstance ([ string $locale ] )

public static IntlBreakIterator createCodePointInstance ( void )

public static IntlBreakIterator createLineInstance ([ string $locale ] )

public static IntlBreakIterator createSentenceInstance ([ string $locale ] )

public static IntlBreakIterator createTitleInstance ([ string $locale ] )

public static IntlBreakIterator createWordInstance ([ string $locale ] )

public int current ( void )

public int first ( void )

public int following ( int $offset )

public int getErrorCode ( void )

int intl_get_error_code ( void )

public string getErrorMessage ( void )

string intl_get_error_message ( void )

public string getLocale ( string $locale_type )

public IntlPartsIterator getPartsIterator ([ int $key_type = IntlPartsIterator::KEY_SEQUENTIAL ] )

public string getText ( void )

public bool isBoundary ( int $offset )

public int last ( void )

public int next ([ int $offset ] )

public int preceding ( int $offset )

public int previous ( void )

public bool setText ( string $text )

}

预定义常量

IntlBreakIterator::DONE

IntlBreakIterator::WORD_NONE

IntlBreakIterator::WORD_NONE_LIMIT

IntlBreakIterator::WORD_NUMBER

IntlBreakIterator::WORD_NUMBER_LIMIT

IntlBreakIterator::WORD_LETTER

IntlBreakIterator::WORD_LETTER_LIMIT

IntlBreakIterator::WORD_KANA

IntlBreakIterator::WORD_KANA_LIMIT

IntlBreakIterator::WORD_IDEO

IntlBreakIterator::WORD_IDEO_LIMIT

IntlBreakIterator::LINE_SOFT

IntlBreakIterator::LINE_SOFT_LIMIT

IntlBreakIterator::LINE_HARD

IntlBreakIterator::LINE_HARD_LIMIT

IntlBreakIterator::SENTENCE_TERM

IntlBreakIterator::SENTENCE_TERM_LIMIT

IntlBreakIterator::SENTENCE_SEP

IntlBreakIterator::SENTENCE_SEP_LIMIT

IntlBreakIterator::__construct

Private constructor for disallowing instantiation

说明

private IntlBreakIterator::__construct ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlBreakIterator::createCharacterInstance

Create break iterator for boundaries of combining character sequences

说明

public static IntlBreakIterator IntlBreakIterator::createCharacterInstance ([ string $locale ] )

Warning

本函数还未编写文档,仅有参数列表。

参数

locale

返回值

IntlBreakIterator::createCodePointInstance

Create break iterator for boundaries of code points

说明

public static IntlBreakIterator IntlBreakIterator::createCodePointInstance ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlBreakIterator::createLineInstance

Create break iterator for logically possible line breaks

说明

public static IntlBreakIterator IntlBreakIterator::createLineInstance ([ string $locale ] )

Warning

本函数还未编写文档,仅有参数列表。

参数

locale

返回值

IntlBreakIterator::createSentenceInstance

Create break iterator for sentence breaks

说明

public static IntlBreakIterator IntlBreakIterator::createSentenceInstance ([ string $locale ] )

Warning

本函数还未编写文档,仅有参数列表。

参数

locale

返回值

IntlBreakIterator::createTitleInstance

Create break iterator for title-casing breaks

说明

public static IntlBreakIterator IntlBreakIterator::createTitleInstance ([ string $locale ] )

Warning

本函数还未编写文档,仅有参数列表。

参数

locale

返回值

IntlBreakIterator::createWordInstance

Create break iterator for word breaks

说明

public static IntlBreakIterator IntlBreakIterator::createWordInstance ([ string $locale ] )

Warning

本函数还未编写文档,仅有参数列表。

参数

locale

返回值

IntlBreakIterator::current

Get index of current position

说明

public int IntlBreakIterator::current ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlBreakIterator::first

Set position to the first character in the text

说明

public int IntlBreakIterator::first ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlBreakIterator::following

Advance the iterator to the first boundary following specified offset

说明

public int IntlBreakIterator::following ( int $offset )

Warning

本函数还未编写文档,仅有参数列表。

参数

offset

返回值

IntlBreakIterator::getErrorCode

intl_get_error_code

Get last error code on the object

说明

面向对象风格 (method):

public int IntlBreakIterator::getErrorCode ( void )

过程化风格:

int intl_get_error_code ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlBreakIterator::getErrorMessage

intl_get_error_message

Get last error message on the object

说明

面向对象风格 (method):

public string IntlBreakIterator::getErrorMessage ( void )

过程化风格:

string intl_get_error_message ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlBreakIterator::getLocale

Get the locale associated with the object

说明

public string IntlBreakIterator::getLocale ( string $locale_type )

Warning

本函数还未编写文档,仅有参数列表。

参数

locale_type

返回值

IntlBreakIterator::getPartsIterator

Create iterator for navigating fragments between boundaries

说明

public IntlPartsIterator IntlBreakIterator::getPartsIterator ([ int $key_type = IntlPartsIterator::KEY_SEQUENTIAL ] )

Warning

本函数还未编写文档,仅有参数列表。

参数

key_type
Optional key type. Possible values are:

  • IntlPartsIterator::KEY_SEQUENTIAL - The default. Sequentially increasing integers used as key.
  • IntlPartsIterator::KEY_LEFT - Byte offset left of current part used as key.
  • IntlPartsIterator::KEY_RIGHT - Byte offset right of current part used as key.

返回值

IntlBreakIterator::getText

Get the text being scanned

说明

public string IntlBreakIterator::getText ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlBreakIterator::isBoundary

Tell whether an offset is a boundaryʼs offset

说明

public bool IntlBreakIterator::isBoundary ( int $offset )

Warning

本函数还未编写文档,仅有参数列表。

参数

offset

返回值

IntlBreakIterator::last

Set the iterator position to index beyond the last character

说明

public int IntlBreakIterator::last ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlBreakIterator::next

Advance the iterator the next boundary

说明

public int IntlBreakIterator::next ([ int $offset ] )

Warning

本函数还未编写文档,仅有参数列表。

参数

offset

返回值

IntlBreakIterator::preceding

Set the iterator position to the first boundary before an offset

说明

public int IntlBreakIterator::preceding ( int $offset )

Warning

本函数还未编写文档,仅有参数列表。

参数

offset

返回值

IntlBreakIterator::previous

Set the iterator position to the boundary immediately before the current

说明

public int IntlBreakIterator::previous ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlBreakIterator::setText

Set the text being scanned

说明

public bool IntlBreakIterator::setText ( string $text )

Warning

本函数还未编写文档,仅有参数列表。

参数

text

返回值

简介

A subclass of IntlBreakIterator that encapsulates ICU break iterators whose behavior is specified using a set of rules. This is the most common kind of break iterators.

These rules are described in the » ICU Boundary Analysis User Guide.

类摘要

IntlRuleBasedBreakIterator

class IntlRuleBasedBreakIterator extends IntlBreakIterator implements Traversable {

/* 继承的常量 */

const integer IntlBreakIterator::DONE = -1 ;

const integer IntlBreakIterator::WORD_NONE = 0 ;

const integer IntlBreakIterator::WORD_NONE_LIMIT = 100 ;

const integer IntlBreakIterator::WORD_NUMBER = 100 ;

const integer IntlBreakIterator::WORD_NUMBER_LIMIT = 200 ;

const integer IntlBreakIterator::WORD_LETTER = 200 ;

const integer IntlBreakIterator::WORD_LETTER_LIMIT = 300 ;

const integer IntlBreakIterator::WORD_KANA = 300 ;

const integer IntlBreakIterator::WORD_KANA_LIMIT = 400 ;

const integer IntlBreakIterator::WORD_IDEO = 400 ;

const integer IntlBreakIterator::WORD_IDEO_LIMIT = 500 ;

const integer IntlBreakIterator::LINE_SOFT = 0 ;

const integer IntlBreakIterator::LINE_SOFT_LIMIT = 100 ;

const integer IntlBreakIterator::LINE_HARD = 100 ;

const integer IntlBreakIterator::LINE_HARD_LIMIT = 200 ;

const integer IntlBreakIterator::SENTENCE_TERM = 0 ;

const integer IntlBreakIterator::SENTENCE_TERM_LIMIT = 100 ;

const integer IntlBreakIterator::SENTENCE_SEP = 100 ;

const integer IntlBreakIterator::SENTENCE_SEP_LIMIT = 200 ;

/* 方法 */

public __construct ( string $rules [, string $areCompiled ] )

public string getBinaryRules ( void )

public string getRules ( void )

public int getRuleStatus ( void )

public array getRuleStatusVec ( void )

/* 继承的方法 */

private IntlBreakIterator::__construct ( void )

public static IntlBreakIterator IntlBreakIterator::createCharacterInstance ([ string $locale ] )

public static IntlBreakIterator IntlBreakIterator::createCodePointInstance ( void )

public static IntlBreakIterator IntlBreakIterator::createLineInstance ([ string $locale ] )

public static IntlBreakIterator IntlBreakIterator::createSentenceInstance ([ string $locale ] )

public static IntlBreakIterator IntlBreakIterator::createTitleInstance ([ string $locale ] )

public static IntlBreakIterator IntlBreakIterator::createWordInstance ([ string $locale ] )

public int IntlBreakIterator::current ( void )

public int IntlBreakIterator::first ( void )

public int IntlBreakIterator::following ( int $offset )

public int IntlBreakIterator::getErrorCode ( void )

int intl_get_error_code ( void )

public string IntlBreakIterator::getErrorMessage ( void )

string intl_get_error_message ( void )

public string IntlBreakIterator::getLocale ( string $locale_type )

public IntlPartsIterator IntlBreakIterator::getPartsIterator ([ int $key_type = IntlPartsIterator::KEY_SEQUENTIAL ] )

public string IntlBreakIterator::getText ( void )

public bool IntlBreakIterator::isBoundary ( int $offset )

public int IntlBreakIterator::last ( void )

public int IntlBreakIterator::next ([ int $offset ] )

public int IntlBreakIterator::preceding ( int $offset )

public int IntlBreakIterator::previous ( void )

public bool IntlBreakIterator::setText ( string $text )

}

IntlRuleBasedBreakIterator::__construct

Create iterator from ruleset

说明

public IntlRuleBasedBreakIterator::__construct ( string $rules [, string $areCompiled ] )

Warning

本函数还未编写文档,仅有参数列表。

参数

rules

areCompiled

返回值

IntlRuleBasedBreakIterator::getBinaryRules

Get the binary form of compiled rules

说明

public string IntlRuleBasedBreakIterator::getBinaryRules ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlRuleBasedBreakIterator::getRules

Get the rule set used to create this object

说明

public string IntlRuleBasedBreakIterator::getRules ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlRuleBasedBreakIterator::getRuleStatus

Get the largest status value from the break rules that determined the current break position

说明

public int IntlRuleBasedBreakIterator::getRuleStatus ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

IntlRuleBasedBreakIterator::getRuleStatusVec

Get the status values from the break rules that determined the current break position

说明

public array IntlRuleBasedBreakIterator::getRuleStatusVec ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

简介

This break iterator identifies the boundaries between UTF-8 code points.

类摘要

IntlCodePointBreakIterator

class IntlCodePointBreakIterator extends IntlBreakIterator implements Traversable {

/* 继承的常量 */

const integer IntlBreakIterator::DONE = -1 ;

const integer IntlBreakIterator::WORD_NONE = 0 ;

const integer IntlBreakIterator::WORD_NONE_LIMIT = 100 ;

const integer IntlBreakIterator::WORD_NUMBER = 100 ;

const integer IntlBreakIterator::WORD_NUMBER_LIMIT = 200 ;

const integer IntlBreakIterator::WORD_LETTER = 200 ;

const integer IntlBreakIterator::WORD_LETTER_LIMIT = 300 ;

const integer IntlBreakIterator::WORD_KANA = 300 ;

const integer IntlBreakIterator::WORD_KANA_LIMIT = 400 ;

const integer IntlBreakIterator::WORD_IDEO = 400 ;

const integer IntlBreakIterator::WORD_IDEO_LIMIT = 500 ;

const integer IntlBreakIterator::LINE_SOFT = 0 ;

const integer IntlBreakIterator::LINE_SOFT_LIMIT = 100 ;

const integer IntlBreakIterator::LINE_HARD = 100 ;

const integer IntlBreakIterator::LINE_HARD_LIMIT = 200 ;

const integer IntlBreakIterator::SENTENCE_TERM = 0 ;

const integer IntlBreakIterator::SENTENCE_TERM_LIMIT = 100 ;

const integer IntlBreakIterator::SENTENCE_SEP = 100 ;

const integer IntlBreakIterator::SENTENCE_SEP_LIMIT = 200 ;

/* 方法 */

public int getLastCodePoint ( void )

/* 继承的方法 */

private IntlBreakIterator::__construct ( void )

public static IntlBreakIterator IntlBreakIterator::createCharacterInstance ([ string $locale ] )

public static IntlBreakIterator IntlBreakIterator::createCodePointInstance ( void )

public static IntlBreakIterator IntlBreakIterator::createLineInstance ([ string $locale ] )

public static IntlBreakIterator IntlBreakIterator::createSentenceInstance ([ string $locale ] )

public static IntlBreakIterator IntlBreakIterator::createTitleInstance ([ string $locale ] )

public static IntlBreakIterator IntlBreakIterator::createWordInstance ([ string $locale ] )

public int IntlBreakIterator::current ( void )

public int IntlBreakIterator::first ( void )

public int IntlBreakIterator::following ( int $offset )

public int IntlBreakIterator::getErrorCode ( void )

int intl_get_error_code ( void )

public string IntlBreakIterator::getErrorMessage ( void )

string intl_get_error_message ( void )

public string IntlBreakIterator::getLocale ( string $locale_type )

public IntlPartsIterator IntlBreakIterator::getPartsIterator ([ int $key_type = IntlPartsIterator::KEY_SEQUENTIAL ] )

public string IntlBreakIterator::getText ( void )

public bool IntlBreakIterator::isBoundary ( int $offset )

public int IntlBreakIterator::last ( void )

public int IntlBreakIterator::next ([ int $offset ] )

public int IntlBreakIterator::preceding ( int $offset )

public int IntlBreakIterator::previous ( void )

public bool IntlBreakIterator::setText ( string $text )

}

IntlCodePointBreakIterator::getLastCodePoint

Get last code point passed over after advancing or receding the iterator

说明

public int IntlCodePointBreakIterator::getLastCodePoint ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

简介

Objects of this class can be obtained from IntlBreakIterator objects. While the break iterators provide a sequence of boundary positions when iterated, IntlPartsIterator objects provide, as a convenience, the text fragments comprehended between two successive boundaries.

The keys may represent the offset of the left boundary, right boundary, or they may just the sequence of non-negative integers. See IntlBreakIterator::getPartsIterator.

类摘要

IntlPartsIterator

class IntlPartsIterator extends IntlIterator implements Iterator {

/* Constants */

const integer IntlPartsIterator::KEY_SEQUENTIAL = 0 ;

const integer IntlPartsIterator::KEY_LEFT = 1 ;

const integer IntlPartsIterator::KEY_RIGHT = 2 ;

/* 方法 */

public IntlBreakIterator getBreakIterator ( void )

/* 继承的方法 */

public mixed IntlIterator::current ( void )

public string IntlIterator::key ( void )

public void IntlIterator::next ( void )

public void IntlIterator::rewind ( void )

public bool IntlIterator::valid ( void )

}

预定义常量

IntlPartsIterator::KEY_SEQUENTIAL

IntlPartsIterator::KEY_LEFT

IntlPartsIterator::KEY_RIGHT

IntlPartsIterator::getBreakIterator

Get IntlBreakIterator backing this parts iterator

说明

public IntlBreakIterator IntlPartsIterator::getBreakIterator ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

简介

类摘要

UConverter

class UConverter {

/* Constants */

const integer UConverter::REASON_UNASSIGNED = 0 ;

const integer UConverter::REASON_ILLEGAL = 1 ;

const integer UConverter::REASON_IRREGULAR = 2 ;

const integer UConverter::REASON_RESET = 3 ;

const integer UConverter::REASON_CLOSE = 4 ;

const integer UConverter::REASON_CLONE = 5 ;

const integer UConverter::UNSUPPORTED_CONVERTER = -1 ;

const integer UConverter::SBCS = 0 ;

const integer UConverter::DBCS = 1 ;

const integer UConverter::MBCS = 2 ;

const integer UConverter::LATIN_1 = 3 ;

const integer UConverter::UTF8 = 4 ;

const integer UConverter::UTF16_BigEndian = 5 ;

const integer UConverter::UTF16_LittleEndian = 6 ;

const integer UConverter::UTF32_BigEndian = 7 ;

const integer UConverter::UTF32_LittleEndian = 8 ;

const integer UConverter::EBCDIC_STATEFUL = 9 ;

const integer UConverter::ISO_2022 = 10 ;

const integer UConverter::LMBCS_1 = 11 ;

const integer UConverter::LMBCS_2 = 12 ;

const integer UConverter::LMBCS_3 = 13 ;

const integer UConverter::LMBCS_4 = 14 ;

const integer UConverter::LMBCS_5 = 15 ;

const integer UConverter::LMBCS_6 = 16 ;

const integer UConverter::LMBCS_8 = 17 ;

const integer UConverter::LMBCS_11 = 18 ;

const integer UConverter::LMBCS_16 = 19 ;

const integer UConverter::LMBCS_17 = 20 ;

const integer UConverter::LMBCS_18 = 21 ;

const integer UConverter::LMBCS_19 = 22 ;

const integer UConverter::LMBCS_LAST = 22 ;

const integer UConverter::HZ = 23 ;

const integer UConverter::SCSU = 24 ;

const integer UConverter::ISCII = 25 ;

const integer UConverter::US_ASCII = 26 ;

const integer UConverter::UTF7 = 27 ;

const integer UConverter::BOCU1 = 28 ;

const integer UConverter::UTF16 = 29 ;

const integer UConverter::UTF32 = 30 ;

const integer UConverter::CESU8 = 31 ;

const integer UConverter::IMAP_MAILBOX = 32 ;

/* 方法 */

public __construct ([ string $destination_encoding [, string $source_encoding ]] )

public string convert ( string $str [, bool $reverse ] )

public mixed fromUCallback ( int $reason , string $source , string $codePoint , int &$error )

public static array getAliases ( string $name )

public static array getAvailable ( void )

public string getDestinationEncoding ( void )

public int getDestinationType ( void )

public int getErrorCode ( void )

public string getErrorMessage ( void )

public string getSourceEncoding ( void )

public int getSourceType ( void )

public static array getStandards ( void )

public string getSubstChars ( void )

public static string reasonText ([ int $reason ] )

public void setDestinationEncoding ( string $encoding )

public void setSourceEncoding ( string $encoding )

public void setSubstChars ( string $chars )

public mixed toUCallback ( int $reason , string $source , string $codeUnits , int &$error )

public static string transcode ( string $str , string $toEncoding , string $fromEncoding [, array $options ] )

}

预定义常量

UConverter::REASON_UNASSIGNED

UConverter::REASON_ILLEGAL

UConverter::REASON_IRREGULAR

UConverter::REASON_RESET

UConverter::REASON_CLOSE

UConverter::REASON_CLONE

UConverter::UNSUPPORTED_CONVERTER

UConverter::SBCS

UConverter::DBCS

UConverter::MBCS

UConverter::LATIN_1

UConverter::UTF8

UConverter::UTF16_BigEndian

UConverter::UTF16_LittleEndian

UConverter::UTF32_BigEndian

UConverter::UTF32_LittleEndian

UConverter::EBCDIC_STATEFUL

UConverter::ISO_2022

UConverter::LMBCS_1

UConverter::LMBCS_2

UConverter::LMBCS_3

UConverter::LMBCS_4

UConverter::LMBCS_5

UConverter::LMBCS_6

UConverter::LMBCS_8

UConverter::LMBCS_11

UConverter::LMBCS_16

UConverter::LMBCS_17

UConverter::LMBCS_18

UConverter::LMBCS_19

UConverter::LMBCS_LAST

UConverter::HZ

UConverter::SCSU

UConverter::ISCII

UConverter::US_ASCII

UConverter::UTF7

UConverter::BOCU1

UConverter::UTF16

UConverter::UTF32

UConverter::CESU8

UConverter::IMAP_MAILBOX

UConverter::__construct

Create UConverter object

说明

public UConverter::__construct ([ string $destination_encoding [, string $source_encoding ]] )

Warning

本函数还未编写文档,仅有参数列表。

参数

destination_encoding

source_encoding

返回值

UConverter::convert

Convert string from one charset to another

说明

public string UConverter::convert ( string $str [, bool $reverse ] )

Warning

本函数还未编写文档,仅有参数列表。

参数

str

reverse

返回值

UConverter::fromUCallback

Default "from" callback function

说明

public mixed UConverter::fromUCallback ( int $reason , string $source , string $codePoint , int &$error )

Warning

本函数还未编写文档,仅有参数列表。

参数

reason

source

codePoint

error

返回值

UConverter::getAliases

Get the aliases of the given name

说明

public static array UConverter::getAliases ( string $name )

Warning

本函数还未编写文档,仅有参数列表。

参数

name

返回值

UConverter::getAvailable

Get the available canonical converter names

说明

public static array UConverter::getAvailable ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

UConverter::getDestinationEncoding

Get the destination encoding

说明

public string UConverter::getDestinationEncoding ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

UConverter::getDestinationType

Get the destination converter type

说明

public int UConverter::getDestinationType ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

UConverter::getErrorCode

intl_get_error_code

Get last error code on the object

说明

public int UConverter::getErrorCode ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

UConverter::getErrorMessage

Get last error message on the object

说明

public string UConverter::getErrorMessage ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

UConverter::getSourceEncoding

Get the source encoding

说明

public string UConverter::getSourceEncoding ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

UConverter::getSourceType

Get the source converter type

说明

public int UConverter::getSourceType ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

UConverter::getStandards

Get standards associated to converter names

说明

public static array UConverter::getStandards ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

UConverter::getSubstChars

Get substitution chars

说明

public string UConverter::getSubstChars ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

UConverter::reasonText

Get string representation of the callback reason

说明

public static string UConverter::reasonText ([ int $reason ] )

Warning

本函数还未编写文档,仅有参数列表。

参数

reason

返回值

UConverter::setDestinationEncoding

Set the destination encoding

说明

public void UConverter::setDestinationEncoding ( string $encoding )

Warning

本函数还未编写文档,仅有参数列表。

参数

encoding

返回值

UConverter::setSourceEncoding

Set the source encoding

说明

public void UConverter::setSourceEncoding ( string $encoding )

Warning

本函数还未编写文档,仅有参数列表。

参数

encoding

返回值

UConverter::setSubstChars

Set the substitution chars

说明

public void UConverter::setSubstChars ( string $chars )

Warning

本函数还未编写文档,仅有参数列表。

参数

chars

返回值

UConverter::toUCallback

Default "to" callback function

说明

public mixed UConverter::toUCallback ( int $reason , string $source , string $codeUnits , int &$error )

Warning

本函数还未编写文档,仅有参数列表。

参数

reason

source

codeUnits

error

返回值

UConverter::transcode

Convert string from one charset to another

说明

public static string UConverter::transcode ( string $str , string $toEncoding , string $fromEncoding [, array $options ] )

Warning

本函数还未编写文档,仅有参数列表。

参数

str

toEncoding

fromEncoding

options

返回值

简介

IntlChar provides access to a number of utility methods that can be used to access information about Unicode characters.

The methods and constants adhere closely to the names and behavior used by the underlying ICU library.

类摘要

IntlChar

class IntlChar {

/* Constants */

const string IntlChar::UNICODE_VERSION = 6.3 ;

const integer IntlChar::CODEPOINT_MIN = 0 ;

const integer IntlChar::CODEPOINT_MAX = 1114111 ;

const float IntlChar::NO_NUMERIC_VALUE = -123456789 ;

const integer IntlChar::PROPERTY_ALPHABETIC = 0 ;

const integer IntlChar::PROPERTY_BINARY_START = 0 ;

const integer IntlChar::PROPERTY_ASCII_HEX_DIGIT = 1 ;

const integer IntlChar::PROPERTY_BIDI_CONTROL = 2 ;

const integer IntlChar::PROPERTY_BIDI_MIRRORED = 3 ;

const integer IntlChar::PROPERTY_DASH = 4 ;

const integer IntlChar::PROPERTY_DEFAULT_IGNORABLE_CODE_POINT = 5 ;

const integer IntlChar::PROPERTY_DEPRECATED = 6 ;

const integer IntlChar::PROPERTY_DIACRITIC = 7 ;

const integer IntlChar::PROPERTY_EXTENDER = 8 ;

const integer IntlChar::PROPERTY_FULL_COMPOSITION_EXCLUSION = 9 ;

const integer IntlChar::PROPERTY_GRAPHEME_BASE = 10 ;

const integer IntlChar::PROPERTY_GRAPHEME_EXTEND = 11 ;

const integer IntlChar::PROPERTY_GRAPHEME_LINK = 12 ;

const integer IntlChar::PROPERTY_HEX_DIGIT = 13 ;

const integer IntlChar::PROPERTY_HYPHEN = 14 ;

const integer IntlChar::PROPERTY_ID_CONTINUE = 15 ;

const integer IntlChar::PROPERTY_ID_START = 16 ;

const integer IntlChar::PROPERTY_IDEOGRAPHIC = 17 ;

const integer IntlChar::PROPERTY_IDS_BINARY_OPERATOR = 18 ;

const integer IntlChar::PROPERTY_IDS_TRINARY_OPERATOR = 19 ;

const integer IntlChar::PROPERTY_JOIN_CONTROL = 20 ;

const integer IntlChar::PROPERTY_LOGICAL_ORDER_EXCEPTION = 21 ;

const integer IntlChar::PROPERTY_LOWERCASE = 22 ;

const integer IntlChar::PROPERTY_MATH = 23 ;

const integer IntlChar::PROPERTY_NONCHARACTER_CODE_POINT = 24 ;

const integer IntlChar::PROPERTY_QUOTATION_MARK = 25 ;

const integer IntlChar::PROPERTY_RADICAL = 26 ;

const integer IntlChar::PROPERTY_SOFT_DOTTED = 27 ;

const integer IntlChar::PROPERTY_TERMINAL_PUNCTUATION = 28 ;

const integer IntlChar::PROPERTY_UNIFIED_IDEOGRAPH = 29 ;

const integer IntlChar::PROPERTY_UPPERCASE = 30 ;

const integer IntlChar::PROPERTY_WHITE_SPACE = 31 ;

const integer IntlChar::PROPERTY_XID_CONTINUE = 32 ;

const integer IntlChar::PROPERTY_XID_START = 33 ;

const integer IntlChar::PROPERTY_CASE_SENSITIVE = 34 ;

const integer IntlChar::PROPERTY_S_TERM = 35 ;

const integer IntlChar::PROPERTY_VARIATION_SELECTOR = 36 ;

const integer IntlChar::PROPERTY_NFD_INERT = 37 ;

const integer IntlChar::PROPERTY_NFKD_INERT = 38 ;

const integer IntlChar::PROPERTY_NFC_INERT = 39 ;

const integer IntlChar::PROPERTY_NFKC_INERT = 40 ;

const integer IntlChar::PROPERTY_SEGMENT_STARTER = 41 ;

const integer IntlChar::PROPERTY_PATTERN_SYNTAX = 42 ;

const integer IntlChar::PROPERTY_PATTERN_WHITE_SPACE = 43 ;

const integer IntlChar::PROPERTY_POSIX_ALNUM = 44 ;

const integer IntlChar::PROPERTY_POSIX_BLANK = 45 ;

const integer IntlChar::PROPERTY_POSIX_GRAPH = 46 ;

const integer IntlChar::PROPERTY_POSIX_PRINT = 47 ;

const integer IntlChar::PROPERTY_POSIX_XDIGIT = 48 ;

const integer IntlChar::PROPERTY_CASED = 49 ;

const integer IntlChar::PROPERTY_CASE_IGNORABLE = 50 ;

const integer IntlChar::PROPERTY_CHANGES_WHEN_LOWERCASED = 51 ;

const integer IntlChar::PROPERTY_CHANGES_WHEN_UPPERCASED = 52 ;

const integer IntlChar::PROPERTY_CHANGES_WHEN_TITLECASED = 53 ;

const integer IntlChar::PROPERTY_CHANGES_WHEN_CASEFOLDED = 54 ;

const integer IntlChar::PROPERTY_CHANGES_WHEN_CASEMAPPED = 55 ;

const integer IntlChar::PROPERTY_CHANGES_WHEN_NFKC_CASEFOLDED = 56 ;

const integer IntlChar::PROPERTY_BINARY_LIMIT = 57 ;

const integer IntlChar::PROPERTY_BIDI_CLASS = 4096 ;

const integer IntlChar::PROPERTY_INT_START = 4096 ;

const integer IntlChar::PROPERTY_BLOCK = 4097 ;

const integer IntlChar::PROPERTY_CANONICAL_COMBINING_CLASS = 4098 ;

const integer IntlChar::PROPERTY_DECOMPOSITION_TYPE = 4099 ;

const integer IntlChar::PROPERTY_EAST_ASIAN_WIDTH = 4100 ;

const integer IntlChar::PROPERTY_GENERAL_CATEGORY = 4101 ;

const integer IntlChar::PROPERTY_JOINING_GROUP = 4102 ;

const integer IntlChar::PROPERTY_JOINING_TYPE = 4103 ;

const integer IntlChar::PROPERTY_LINE_BREAK = 4104 ;

const integer IntlChar::PROPERTY_NUMERIC_TYPE = 4105 ;

const integer IntlChar::PROPERTY_SCRIPT = 4106 ;

const integer IntlChar::PROPERTY_HANGUL_SYLLABLE_TYPE = 4107 ;

const integer IntlChar::PROPERTY_NFD_QUICK_CHECK = 4108 ;

const integer IntlChar::PROPERTY_NFKD_QUICK_CHECK = 4109 ;

const integer IntlChar::PROPERTY_NFC_QUICK_CHECK = 4110 ;

const integer IntlChar::PROPERTY_NFKC_QUICK_CHECK = 4111 ;

const integer IntlChar::PROPERTY_LEAD_CANONICAL_COMBINING_CLASS = 4112 ;

const integer IntlChar::PROPERTY_TRAIL_CANONICAL_COMBINING_CLASS = 4113 ;

const integer IntlChar::PROPERTY_GRAPHEME_CLUSTER_BREAK = 4114 ;

const integer IntlChar::PROPERTY_SENTENCE_BREAK = 4115 ;

const integer IntlChar::PROPERTY_WORD_BREAK = 4116 ;

const integer IntlChar::PROPERTY_BIDI_PAIRED_BRACKET_TYPE = 4117 ;

const integer IntlChar::PROPERTY_INT_LIMIT = 4118 ;

const integer IntlChar::PROPERTY_GENERAL_CATEGORY_MASK = 8192 ;

const integer IntlChar::PROPERTY_MASK_START = 8192 ;

const integer IntlChar::PROPERTY_MASK_LIMIT = 8193 ;

const integer IntlChar::PROPERTY_NUMERIC_VALUE = 12288 ;

const integer IntlChar::PROPERTY_DOUBLE_START = 12288 ;

const integer IntlChar::PROPERTY_DOUBLE_LIMIT = 12289 ;

const integer IntlChar::PROPERTY_AGE = 16384 ;

const integer IntlChar::PROPERTY_STRING_START = 16384 ;

const integer IntlChar::PROPERTY_BIDI_MIRRORING_GLYPH = 16385 ;

const integer IntlChar::PROPERTY_CASE_FOLDING = 16386 ;

const integer IntlChar::PROPERTY_ISO_COMMENT = 16387 ;

const integer IntlChar::PROPERTY_LOWERCASE_MAPPING = 16388 ;

const integer IntlChar::PROPERTY_NAME = 16389 ;

const integer IntlChar::PROPERTY_SIMPLE_CASE_FOLDING = 16390 ;

const integer IntlChar::PROPERTY_SIMPLE_LOWERCASE_MAPPING = 16391 ;

const integer IntlChar::PROPERTY_SIMPLE_TITLECASE_MAPPING = 16392 ;

const integer IntlChar::PROPERTY_SIMPLE_UPPERCASE_MAPPING = 16393 ;

const integer IntlChar::PROPERTY_TITLECASE_MAPPING = 16394 ;

const integer IntlChar::PROPERTY_UNICODE_1_NAME = 16395 ;

const integer IntlChar::PROPERTY_UPPERCASE_MAPPING = 16396 ;

const integer IntlChar::PROPERTY_BIDI_PAIRED_BRACKET = 16397 ;

const integer IntlChar::PROPERTY_STRING_LIMIT = 16398 ;

const integer IntlChar::PROPERTY_SCRIPT_EXTENSIONS = 28672 ;

const integer IntlChar::PROPERTY_OTHER_PROPERTY_START = 28672 ;

const integer IntlChar::PROPERTY_OTHER_PROPERTY_LIMIT = 28673 ;

const integer IntlChar::PROPERTY_INVALID_CODE = -1 ;

const integer IntlChar::CHAR_CATEGORY_UNASSIGNED = 0 ;

const integer IntlChar::CHAR_CATEGORY_GENERAL_OTHER_TYPES = 0 ;

const integer IntlChar::CHAR_CATEGORY_UPPERCASE_LETTER = 1 ;

const integer IntlChar::CHAR_CATEGORY_LOWERCASE_LETTER = 2 ;

const integer IntlChar::CHAR_CATEGORY_TITLECASE_LETTER = 3 ;

const integer IntlChar::CHAR_CATEGORY_MODIFIER_LETTER = 4 ;

const integer IntlChar::CHAR_CATEGORY_OTHER_LETTER = 5 ;

const integer IntlChar::CHAR_CATEGORY_NON_SPACING_MARK = 6 ;

const integer IntlChar::CHAR_CATEGORY_ENCLOSING_MARK = 7 ;

const integer IntlChar::CHAR_CATEGORY_COMBINING_SPACING_MARK = 8 ;

const integer IntlChar::CHAR_CATEGORY_DECIMAL_DIGIT_NUMBER = 9 ;

const integer IntlChar::CHAR_CATEGORY_LETTER_NUMBER = 10 ;

const integer IntlChar::CHAR_CATEGORY_OTHER_NUMBER = 11 ;

const integer IntlChar::CHAR_CATEGORY_SPACE_SEPARATOR = 12 ;

const integer IntlChar::CHAR_CATEGORY_LINE_SEPARATOR = 13 ;

const integer IntlChar::CHAR_CATEGORY_PARAGRAPH_SEPARATOR = 14 ;

const integer IntlChar::CHAR_CATEGORY_CONTROL_CHAR = 15 ;

const integer IntlChar::CHAR_CATEGORY_FORMAT_CHAR = 16 ;

const integer IntlChar::CHAR_CATEGORY_PRIVATE_USE_CHAR = 17 ;

const integer IntlChar::CHAR_CATEGORY_SURROGATE = 18 ;

const integer IntlChar::CHAR_CATEGORY_DASH_PUNCTUATION = 19 ;

const integer IntlChar::CHAR_CATEGORY_START_PUNCTUATION = 20 ;

const integer IntlChar::CHAR_CATEGORY_END_PUNCTUATION = 21 ;

const integer IntlChar::CHAR_CATEGORY_CONNECTOR_PUNCTUATION = 22 ;

const integer IntlChar::CHAR_CATEGORY_OTHER_PUNCTUATION = 23 ;

const integer IntlChar::CHAR_CATEGORY_MATH_SYMBOL = 24 ;

const integer IntlChar::CHAR_CATEGORY_CURRENCY_SYMBOL = 25 ;

const integer IntlChar::CHAR_CATEGORY_MODIFIER_SYMBOL = 26 ;

const integer IntlChar::CHAR_CATEGORY_OTHER_SYMBOL = 27 ;

const integer IntlChar::CHAR_CATEGORY_INITIAL_PUNCTUATION = 28 ;

const integer IntlChar::CHAR_CATEGORY_FINAL_PUNCTUATION = 29 ;

const integer IntlChar::CHAR_CATEGORY_CHAR_CATEGORY_COUNT = 30 ;

const integer IntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT = 0 ;

const integer IntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT = 1 ;

const integer IntlChar::CHAR_DIRECTION_EUROPEAN_NUMBER = 2 ;

const integer IntlChar::CHAR_DIRECTION_EUROPEAN_NUMBER_SEPARATOR = 3 ;

const integer IntlChar::CHAR_DIRECTION_EUROPEAN_NUMBER_TERMINATOR = 4 ;

const integer IntlChar::CHAR_DIRECTION_ARABIC_NUMBER = 5 ;

const integer IntlChar::CHAR_DIRECTION_COMMON_NUMBER_SEPARATOR = 6 ;

const integer IntlChar::CHAR_DIRECTION_BLOCK_SEPARATOR = 7 ;

const integer IntlChar::CHAR_DIRECTION_SEGMENT_SEPARATOR = 8 ;

const integer IntlChar::CHAR_DIRECTION_WHITE_SPACE_NEUTRAL = 9 ;

const integer IntlChar::CHAR_DIRECTION_OTHER_NEUTRAL = 10 ;

const integer IntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT_EMBEDDING = 11 ;

const integer IntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT_OVERRIDE = 12 ;

const integer IntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT_ARABIC = 13 ;

const integer IntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT_EMBEDDING = 14 ;

const integer IntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT_OVERRIDE = 15 ;

const integer IntlChar::CHAR_DIRECTION_POP_DIRECTIONAL_FORMAT = 16 ;

const integer IntlChar::CHAR_DIRECTION_DIR_NON_SPACING_MARK = 17 ;

const integer IntlChar::CHAR_DIRECTION_BOUNDARY_NEUTRAL = 18 ;

const integer IntlChar::CHAR_DIRECTION_FIRST_STRONG_ISOLATE = 19 ;

const integer IntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT_ISOLATE = 20 ;

const integer IntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT_ISOLATE = 21 ;

const integer IntlChar::CHAR_DIRECTION_POP_DIRECTIONAL_ISOLATE = 22 ;

const integer IntlChar::CHAR_DIRECTION_CHAR_DIRECTION_COUNT = 23 ;

const integer IntlChar::BLOCK_CODE_NO_BLOCK = 0 ;

const integer IntlChar::BLOCK_CODE_BASIC_LATIN = 1 ;

const integer IntlChar::BLOCK_CODE_LATIN_1_SUPPLEMENT = 2 ;

const integer IntlChar::BLOCK_CODE_LATIN_EXTENDED_A = 3 ;

const integer IntlChar::BLOCK_CODE_LATIN_EXTENDED_B = 4 ;

const integer IntlChar::BLOCK_CODE_IPA_EXTENSIONS = 5 ;

const integer IntlChar::BLOCK_CODE_SPACING_MODIFIER_LETTERS = 6 ;

const integer IntlChar::BLOCK_CODE_COMBINING_DIACRITICAL_MARKS = 7 ;

const integer IntlChar::BLOCK_CODE_GREEK = 8 ;

const integer IntlChar::BLOCK_CODE_CYRILLIC = 9 ;

const integer IntlChar::BLOCK_CODE_ARMENIAN = 10 ;

const integer IntlChar::BLOCK_CODE_HEBREW = 11 ;

const integer IntlChar::BLOCK_CODE_ARABIC = 12 ;

const integer IntlChar::BLOCK_CODE_SYRIAC = 13 ;

const integer IntlChar::BLOCK_CODE_THAANA = 14 ;

const integer IntlChar::BLOCK_CODE_DEVANAGARI = 15 ;

const integer IntlChar::BLOCK_CODE_BENGALI = 16 ;

const integer IntlChar::BLOCK_CODE_GURMUKHI = 17 ;

const integer IntlChar::BLOCK_CODE_GUJARATI = 18 ;

const integer IntlChar::BLOCK_CODE_ORIYA = 19 ;

const integer IntlChar::BLOCK_CODE_TAMIL = 20 ;

const integer IntlChar::BLOCK_CODE_TELUGU = 21 ;

const integer IntlChar::BLOCK_CODE_KANNADA = 22 ;

const integer IntlChar::BLOCK_CODE_MALAYALAM = 23 ;

const integer IntlChar::BLOCK_CODE_SINHALA = 24 ;

const integer IntlChar::BLOCK_CODE_THAI = 25 ;

const integer IntlChar::BLOCK_CODE_LAO = 26 ;

const integer IntlChar::BLOCK_CODE_TIBETAN = 27 ;

const integer IntlChar::BLOCK_CODE_MYANMAR = 28 ;

const integer IntlChar::BLOCK_CODE_GEORGIAN = 29 ;

const integer IntlChar::BLOCK_CODE_HANGUL_JAMO = 30 ;

const integer IntlChar::BLOCK_CODE_ETHIOPIC = 31 ;

const integer IntlChar::BLOCK_CODE_CHEROKEE = 32 ;

const integer IntlChar::BLOCK_CODE_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS = 33 ;

const integer IntlChar::BLOCK_CODE_OGHAM = 34 ;

const integer IntlChar::BLOCK_CODE_RUNIC = 35 ;

const integer IntlChar::BLOCK_CODE_KHMER = 36 ;

const integer IntlChar::BLOCK_CODE_MONGOLIAN = 37 ;

const integer IntlChar::BLOCK_CODE_LATIN_EXTENDED_ADDITIONAL = 38 ;

const integer IntlChar::BLOCK_CODE_GREEK_EXTENDED = 39 ;

const integer IntlChar::BLOCK_CODE_GENERAL_PUNCTUATION = 40 ;

const integer IntlChar::BLOCK_CODE_SUPERSCRIPTS_AND_SUBSCRIPTS = 41 ;

const integer IntlChar::BLOCK_CODE_CURRENCY_SYMBOLS = 42 ;

const integer IntlChar::BLOCK_CODE_COMBINING_MARKS_FOR_SYMBOLS = 43 ;

const integer IntlChar::BLOCK_CODE_LETTERLIKE_SYMBOLS = 44 ;

const integer IntlChar::BLOCK_CODE_NUMBER_FORMS = 45 ;

const integer IntlChar::BLOCK_CODE_ARROWS = 46 ;

const integer IntlChar::BLOCK_CODE_MATHEMATICAL_OPERATORS = 47 ;

const integer IntlChar::BLOCK_CODE_MISCELLANEOUS_TECHNICAL = 48 ;

const integer IntlChar::BLOCK_CODE_CONTROL_PICTURES = 49 ;

const integer IntlChar::BLOCK_CODE_OPTICAL_CHARACTER_RECOGNITION = 50 ;

const integer IntlChar::BLOCK_CODE_ENCLOSED_ALPHANUMERICS = 51 ;

const integer IntlChar::BLOCK_CODE_BOX_DRAWING = 52 ;

const integer IntlChar::BLOCK_CODE_BLOCK_ELEMENTS = 53 ;

const integer IntlChar::BLOCK_CODE_GEOMETRIC_SHAPES = 54 ;

const integer IntlChar::BLOCK_CODE_MISCELLANEOUS_SYMBOLS = 55 ;

const integer IntlChar::BLOCK_CODE_DINGBATS = 56 ;

const integer IntlChar::BLOCK_CODE_BRAILLE_PATTERNS = 57 ;

const integer IntlChar::BLOCK_CODE_CJK_RADICALS_SUPPLEMENT = 58 ;

const integer IntlChar::BLOCK_CODE_KANGXI_RADICALS = 59 ;

const integer IntlChar::BLOCK_CODE_IDEOGRAPHIC_DESCRIPTION_CHARACTERS = 60 ;

const integer IntlChar::BLOCK_CODE_CJK_SYMBOLS_AND_PUNCTUATION = 61 ;

const integer IntlChar::BLOCK_CODE_HIRAGANA = 62 ;

const integer IntlChar::BLOCK_CODE_KATAKANA = 63 ;

const integer IntlChar::BLOCK_CODE_BOPOMOFO = 64 ;

const integer IntlChar::BLOCK_CODE_HANGUL_COMPATIBILITY_JAMO = 65 ;

const integer IntlChar::BLOCK_CODE_KANBUN = 66 ;

const integer IntlChar::BLOCK_CODE_BOPOMOFO_EXTENDED = 67 ;

const integer IntlChar::BLOCK_CODE_ENCLOSED_CJK_LETTERS_AND_MONTHS = 68 ;

const integer IntlChar::BLOCK_CODE_CJK_COMPATIBILITY = 69 ;

const integer IntlChar::BLOCK_CODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A = 70 ;

const integer IntlChar::BLOCK_CODE_CJK_UNIFIED_IDEOGRAPHS = 71 ;

const integer IntlChar::BLOCK_CODE_YI_SYLLABLES = 72 ;

const integer IntlChar::BLOCK_CODE_YI_RADICALS = 73 ;

const integer IntlChar::BLOCK_CODE_HANGUL_SYLLABLES = 74 ;

const integer IntlChar::BLOCK_CODE_HIGH_SURROGATES = 75 ;

const integer IntlChar::BLOCK_CODE_HIGH_PRIVATE_USE_SURROGATES = 76 ;

const integer IntlChar::BLOCK_CODE_LOW_SURROGATES = 77 ;

const integer IntlChar::BLOCK_CODE_PRIVATE_USE_AREA = 78 ;

const integer IntlChar::BLOCK_CODE_PRIVATE_USE = 78 ;

const integer IntlChar::BLOCK_CODE_CJK_COMPATIBILITY_IDEOGRAPHS = 79 ;

const integer IntlChar::BLOCK_CODE_ALPHABETIC_PRESENTATION_FORMS = 80 ;

const integer IntlChar::BLOCK_CODE_ARABIC_PRESENTATION_FORMS_A = 81 ;

const integer IntlChar::BLOCK_CODE_COMBINING_HALF_MARKS = 82 ;

const integer IntlChar::BLOCK_CODE_CJK_COMPATIBILITY_FORMS = 83 ;

const integer IntlChar::BLOCK_CODE_SMALL_FORM_VARIANTS = 84 ;

const integer IntlChar::BLOCK_CODE_ARABIC_PRESENTATION_FORMS_B = 85 ;

const integer IntlChar::BLOCK_CODE_SPECIALS = 86 ;

const integer IntlChar::BLOCK_CODE_HALFWIDTH_AND_FULLWIDTH_FORMS = 87 ;

const integer IntlChar::BLOCK_CODE_OLD_ITALIC = 88 ;

const integer IntlChar::BLOCK_CODE_GOTHIC = 89 ;

const integer IntlChar::BLOCK_CODE_DESERET = 90 ;

const integer IntlChar::BLOCK_CODE_BYZANTINE_MUSICAL_SYMBOLS = 91 ;

const integer IntlChar::BLOCK_CODE_MUSICAL_SYMBOLS = 92 ;

const integer IntlChar::BLOCK_CODE_MATHEMATICAL_ALPHANUMERIC_SYMBOLS = 93 ;

const integer IntlChar::BLOCK_CODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B = 94 ;

const integer IntlChar::BLOCK_CODE_CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT = 95 ;

const integer IntlChar::BLOCK_CODE_TAGS = 96 ;

const integer IntlChar::BLOCK_CODE_CYRILLIC_SUPPLEMENT = 97 ;

const integer IntlChar::BLOCK_CODE_CYRILLIC_SUPPLEMENTARY = 97 ;

const integer IntlChar::BLOCK_CODE_TAGALOG = 98 ;

const integer IntlChar::BLOCK_CODE_HANUNOO = 99 ;

const integer IntlChar::BLOCK_CODE_BUHID = 100 ;

const integer IntlChar::BLOCK_CODE_TAGBANWA = 101 ;

const integer IntlChar::BLOCK_CODE_MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A = 102 ;

const integer IntlChar::BLOCK_CODE_SUPPLEMENTAL_ARROWS_A = 103 ;

const integer IntlChar::BLOCK_CODE_SUPPLEMENTAL_ARROWS_B = 104 ;

const integer IntlChar::BLOCK_CODE_MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B = 105 ;

const integer IntlChar::BLOCK_CODE_SUPPLEMENTAL_MATHEMATICAL_OPERATORS = 106 ;

const integer IntlChar::BLOCK_CODE_KATAKANA_PHONETIC_EXTENSIONS = 107 ;

const integer IntlChar::BLOCK_CODE_VARIATION_SELECTORS = 108 ;

const integer IntlChar::BLOCK_CODE_SUPPLEMENTARY_PRIVATE_USE_AREA_A = 109 ;

const integer IntlChar::BLOCK_CODE_SUPPLEMENTARY_PRIVATE_USE_AREA_B = 110 ;

const integer IntlChar::BLOCK_CODE_LIMBU = 111 ;

const integer IntlChar::BLOCK_CODE_TAI_LE = 112 ;

const integer IntlChar::BLOCK_CODE_KHMER_SYMBOLS = 113 ;

const integer IntlChar::BLOCK_CODE_PHONETIC_EXTENSIONS = 114 ;

const integer IntlChar::BLOCK_CODE_MISCELLANEOUS_SYMBOLS_AND_ARROWS = 115 ;

const integer IntlChar::BLOCK_CODE_YIJING_HEXAGRAM_SYMBOLS = 116 ;

const integer IntlChar::BLOCK_CODE_LINEAR_B_SYLLABARY = 117 ;

const integer IntlChar::BLOCK_CODE_LINEAR_B_IDEOGRAMS = 118 ;

const integer IntlChar::BLOCK_CODE_AEGEAN_NUMBERS = 119 ;

const integer IntlChar::BLOCK_CODE_UGARITIC = 120 ;

const integer IntlChar::BLOCK_CODE_SHAVIAN = 121 ;

const integer IntlChar::BLOCK_CODE_OSMANYA = 122 ;

const integer IntlChar::BLOCK_CODE_CYPRIOT_SYLLABARY = 123 ;

const integer IntlChar::BLOCK_CODE_TAI_XUAN_JING_SYMBOLS = 124 ;

const integer IntlChar::BLOCK_CODE_VARIATION_SELECTORS_SUPPLEMENT = 125 ;

const integer IntlChar::BLOCK_CODE_ANCIENT_GREEK_MUSICAL_NOTATION = 126 ;

const integer IntlChar::BLOCK_CODE_ANCIENT_GREEK_NUMBERS = 127 ;

const integer IntlChar::BLOCK_CODE_ARABIC_SUPPLEMENT = 128 ;

const integer IntlChar::BLOCK_CODE_BUGINESE = 129 ;

const integer IntlChar::BLOCK_CODE_CJK_STROKES = 130 ;

const integer IntlChar::BLOCK_CODE_COMBINING_DIACRITICAL_MARKS_SUPPLEMENT = 131 ;

const integer IntlChar::BLOCK_CODE_COPTIC = 132 ;

const integer IntlChar::BLOCK_CODE_ETHIOPIC_EXTENDED = 133 ;

const integer IntlChar::BLOCK_CODE_ETHIOPIC_SUPPLEMENT = 134 ;

const integer IntlChar::BLOCK_CODE_GEORGIAN_SUPPLEMENT = 135 ;

const integer IntlChar::BLOCK_CODE_GLAGOLITIC = 136 ;

const integer IntlChar::BLOCK_CODE_KHAROSHTHI = 137 ;

const integer IntlChar::BLOCK_CODE_MODIFIER_TONE_LETTERS = 138 ;

const integer IntlChar::BLOCK_CODE_NEW_TAI_LUE = 139 ;

const integer IntlChar::BLOCK_CODE_OLD_PERSIAN = 140 ;

const integer IntlChar::BLOCK_CODE_PHONETIC_EXTENSIONS_SUPPLEMENT = 141 ;

const integer IntlChar::BLOCK_CODE_SUPPLEMENTAL_PUNCTUATION = 142 ;

const integer IntlChar::BLOCK_CODE_SYLOTI_NAGRI = 143 ;

const integer IntlChar::BLOCK_CODE_TIFINAGH = 144 ;

const integer IntlChar::BLOCK_CODE_VERTICAL_FORMS = 145 ;

const integer IntlChar::BLOCK_CODE_NKO = 146 ;

const integer IntlChar::BLOCK_CODE_BALINESE = 147 ;

const integer IntlChar::BLOCK_CODE_LATIN_EXTENDED_C = 148 ;

const integer IntlChar::BLOCK_CODE_LATIN_EXTENDED_D = 149 ;

const integer IntlChar::BLOCK_CODE_PHAGS_PA = 150 ;

const integer IntlChar::BLOCK_CODE_PHOENICIAN = 151 ;

const integer IntlChar::BLOCK_CODE_CUNEIFORM = 152 ;

const integer IntlChar::BLOCK_CODE_CUNEIFORM_NUMBERS_AND_PUNCTUATION = 153 ;

const integer IntlChar::BLOCK_CODE_COUNTING_ROD_NUMERALS = 154 ;

const integer IntlChar::BLOCK_CODE_SUNDANESE = 155 ;

const integer IntlChar::BLOCK_CODE_LEPCHA = 156 ;

const integer IntlChar::BLOCK_CODE_OL_CHIKI = 157 ;

const integer IntlChar::BLOCK_CODE_CYRILLIC_EXTENDED_A = 158 ;

const integer IntlChar::BLOCK_CODE_VAI = 159 ;

const integer IntlChar::BLOCK_CODE_CYRILLIC_EXTENDED_B = 160 ;

const integer IntlChar::BLOCK_CODE_SAURASHTRA = 161 ;

const integer IntlChar::BLOCK_CODE_KAYAH_LI = 162 ;

const integer IntlChar::BLOCK_CODE_REJANG = 163 ;

const integer IntlChar::BLOCK_CODE_CHAM = 164 ;

const integer IntlChar::BLOCK_CODE_ANCIENT_SYMBOLS = 165 ;

const integer IntlChar::BLOCK_CODE_PHAISTOS_DISC = 166 ;

const integer IntlChar::BLOCK_CODE_LYCIAN = 167 ;

const integer IntlChar::BLOCK_CODE_CARIAN = 168 ;

const integer IntlChar::BLOCK_CODE_LYDIAN = 169 ;

const integer IntlChar::BLOCK_CODE_MAHJONG_TILES = 170 ;

const integer IntlChar::BLOCK_CODE_DOMINO_TILES = 171 ;

const integer IntlChar::BLOCK_CODE_SAMARITAN = 172 ;

const integer IntlChar::BLOCK_CODE_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS_EXTENDED = 173 ;

const integer IntlChar::BLOCK_CODE_TAI_THAM = 174 ;

const integer IntlChar::BLOCK_CODE_VEDIC_EXTENSIONS = 175 ;

const integer IntlChar::BLOCK_CODE_LISU = 176 ;

const integer IntlChar::BLOCK_CODE_BAMUM = 177 ;

const integer IntlChar::BLOCK_CODE_COMMON_INDIC_NUMBER_FORMS = 178 ;

const integer IntlChar::BLOCK_CODE_DEVANAGARI_EXTENDED = 179 ;

const integer IntlChar::BLOCK_CODE_HANGUL_JAMO_EXTENDED_A = 180 ;

const integer IntlChar::BLOCK_CODE_JAVANESE = 181 ;

const integer IntlChar::BLOCK_CODE_MYANMAR_EXTENDED_A = 182 ;

const integer I