📄 class.collator.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>The Collator class</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.intl-is-failure.html">intl_is_failure</a></div> <div class="next" style="text-align: right; float: right;"><a href="collator.asort.html">Collator::asort</a></div> <div class="up"><a href="book.intl.html">intl</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div> <h1 class="title">The Collator class</h1> <div class="partintro"> <div id="collator.intro" class="section"> <h2 class="title">Introduction</h2> <p class="para"> Provides string comparison capability with support for appropriate locale-sensitive sort orderings. </p> </div> <div id="collator.synopsis" class="section"> <h2 class="title">Class synopsis</h2> <div class="classsynopsis"> <div class="ooclass"> <b class="classname">Collator</b> </div> <div class="classsynopsisinfo"> <span class="ooclass"> <b class="classname">Collator</b> </span> {</div> <div class="classsynopsisinfo classsynopsisinfo_comment">/* Methods */</div> <div class="constructorsynopsis dc-description"> <span class="methodname"><b><a href="collator.construct.html" class="function">Collator::__construct</a></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$locale</tt></span> )</div> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><b><a href="collator.asort.html" class="function">Collator::asort</a></b></span> ( <span class="methodparam"><span class="type">array</span> <tt class="parameter reference">&$arr</tt></span> [, <span class="methodparam"><span class="type">integer</span> <tt class="parameter">$sort_flag</tt></span> ] )</div><div class="methodsynopsis dc-description"> <span class="type">integer</span> <span class="methodname"><b><a href="collator.compare.html" class="function">Collator::compare</a></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$str1</tt></span> , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$str2</tt></span> )</div><div class="methodsynopsis dc-description"> <span class="modifier">static</span> <span class="type">Collator</span> <span class="methodname"><b><a href="collator.create.html" class="function">Collator::create</a></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$locale</tt></span> )</div><div class="methodsynopsis dc-description"> <span class="type">integer</span> <span class="methodname"><b><a href="collator.getattribute.html" class="function">Collator::getAttribute</a></b></span> ( <span class="methodparam"><span class="type">integer</span> <tt class="parameter">$attr</tt></span> )</div><div class="methodsynopsis dc-description"> <span class="type">integer</span> <span class="methodname"><b><a href="collator.geterrorcode.html" class="function">Collator::getErrorCode</a></b></span> ( <span class="methodparam">void</span> )</div><div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><b><a href="collator.geterrormessage.html" class="function">Collator::getErrorMessage</a></b></span> ( <span class="methodparam">void</span> )</div><div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><b><a href="collator.getlocale.html" class="function">Collator::getLocale</a></b></span> ([ <span class="methodparam"><span class="type">integer</span> <tt class="parameter">$type</tt></span> ] )</div><div class="methodsynopsis dc-description"> <span class="type">integer</span> <span class="methodname"><b><a href="collator.getstrength.html" class="function">Collator::getStrength</a></b></span> ( <span class="methodparam">void</span> )</div><div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><b><a href="collator.setattribute.html" class="function">Collator::setAttribute</a></b></span> ( <span class="methodparam"><span class="type">integer</span> <tt class="parameter">$attr</tt></span> , <span class="methodparam"><span class="type">integer</span> <tt class="parameter">$val</tt></span> )</div><div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><b><a href="collator.setstrength.html" class="function">Collator::setStrength</a></b></span> ( <span class="methodparam"><span class="type">integer</span> <tt class="parameter">$strength</tt></span> )</div><div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><b><a href="collator.sortwithsortkeys.html" class="function">Collator::sortWithSortKeys</a></b></span> ( <span class="methodparam"><span class="type">array</span> <tt class="parameter reference">&$arr</tt></span> )</div><div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><b><a href="collator.sort.html" class="function">Collator::sort</a></b></span> ( <span class="methodparam"><span class="type">array</span> <tt class="parameter reference">&$arr</tt></span> [, <span class="methodparam"><span class="type">integer</span> <tt class="parameter">$sort_flag</tt></span> ] )</div> }</div> </div> <div id="intl.collator-constants" class="section"> <h2 class="title">Predefined Constants</h2> <p class="para"> <dl> <dt> <span class="term"> <b><tt>Collator::FRENCH_COLLATION</tt></b> (<a href="language.types.integer.html" class="type integer">integer</a>) </span> <dd> <p class="para"> Sort strings with different accents from the back of the string. This attribute is automatically set to <em class="emphasis">On</em> 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 <em class="emphasis">On</em>, but sort key length is unaffected. Possible values are: <ul class="simplelist"> <li class="member"><b><tt>Collator::ON</tt></b></li> <li class="member"><b><tt>Collator::OFF</tt></b>(default)</li> <li class="member"><b><tt>Collator::DEFAULT_VALUE</tt></b></li> </ul> </p> <p class="para"> <div class="example"> <p><b>Example #1 FRENCH_COLLATION rules</b></p> <div class="example-contents"><p> <ul class="simplelist"> <li class="member">F=OFF cote < cot茅 < c么te < c么t茅 </li> <li class="member">F=ON cote < c么te < cot茅 < c么t茅</li> </ul> </p></div> </div> </p> </dd> </dt> <dt> <span class="term"> <b><tt>Collator::ALTERNATE_HANDLING</tt></b> (<a href="language.types.integer.html" class="type integer">integer</a>) </span> <dd> <p class="para"> The Alternate attribute is used to control the handling of the socalled variable characters in the UCA: whitespace, punctuation and symbols. If Alternate is set to <em class="emphasis">NonIgnorable</em> (N), then differences among these characters are of the same importance as differences among letters. If Alternate is set to <em class="emphasis">Shifted</em> (S), then these characters are of only minor importance. The <em class="emphasis">Shifted</em> value is often used in combination with <em class="emphasis">Strength</em> 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 <a href="http://www.unicode.org/reports/tr10/" class="link external">» UCA</a> . The reason the Alternate values are not simply <em class="emphasis">On</em> and <em class="emphasis">Off</em> 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. </p> <p class="para"> Possible values are: <ul class="simplelist"> <li class="member"><b><tt>Collator::NON_IGNORABLE</tt></b>(default)</li> <li class="member"><b><tt>Collator::SHIFTED</tt></b></li> <li class="member"><b><tt>Collator::DEFAULT_VALUE</tt></b></li> </ul> </p> <p class="para"> <div class="example"> <p><b>Example #2 ALTERNATE_HANDLING rules</b></p> <div class="example-contents"><p> <ul class="simplelist"> <li class="member"> S=3, A=N di Silva < Di Silva < diSilva < U.S.A. < USA </li> <li class="member"> S=3, A=S di Silva = diSilva < Di Silva < U.S.A. = USA </li> <li class="member"> S=4, A=S di Silva < diSilva < Di Silva < U.S.A. < USA </li> </ul> </p></div> </div> </p> </dd> </dt> <dt> <span class="term"> <b><tt>Collator::CASE_FIRST</tt></b> (<a href="language.types.integer.html" class="type integer">integer</a>) </span> <dd> <p class="para"> 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 <em class="emphasis">Uppercase_First</em> (U) and <em class="emphasis">Lowercase_First</em> (L), plus the standard <em class="emphasis">Default</em> and <em class="emphasis">Off</em>. 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. </p> <p class="para"> Possible values are: <ul class="simplelist"> <li class="member"><b><tt>Collator::OFF</tt></b>(default)</li> <li class="member"><b><tt>Collator::LOWER_FIRST</tt></b></li> <li class="member"><b><tt>Collator::UPPER_FIRST</tt></b></li> <li class="member"><b><tt>Collator:DEFAULT</tt></b></li> </ul> </p> <p class="para"> <div class="example"> <p><b>Example #3 CASE_FIRST rules</b></p> <div class="example-contents"><p> <ul class="simplelist"> <li class="member">C=X or C=L "china" < "China" < "denmark" < "Denmark"</li> <li class="member">C=U "China" < "china" < "Denmark" < "denmark"</li> </ul> </p></div> </div> </p> </dd> </dt> <dt> <span class="term"> <b><tt>Collator::CASE_LEVEL</tt></b> (<a href="language.types.integer.html" class="type integer">integer</a>) </span> <dd> <p class="para"> The Case_Level attribute is used when ignoring accents but not case. In such a situation, set Strength to be <em class="emphasis">Primary</em>, and Case_Level to be <em class="emphasis">On</em>. 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 <em class="emphasis">On</em>. </p> <p class="para"> Possible values are: <ul class="simplelist"> <li class="member"><b><tt>Collator::OFF</tt></b>(default)</li> <li class="member"><b><tt>Collator::ON</tt></b></li> <li class="member"><b><tt>Collator::DEFAULT_VALUE</tt></b></li> </ul> </p> <p class="para"> <div class="example"> <p><b>Example #4 CASE_LEVEL rules</b></p> <div class="example-contents"><p> <ul class="simplelist"> <li class="member">S=1, E=X role = Role = r么le</li> <li class="member">S=1, E=O role = r么le < Role</li> </ul> </p></div> </div> </p> </dd> </dt> <dt> <span class="term"> <b><tt>Collator::NORMALIZATION_MODE</tt></b> (<a href="language.types.integer.html" class="type integer">integer</a>) </span> <dd> <p class="para"> 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 <em class="emphasis">On</em>, then the best results are guaranteed for all possible text input. There is a medium string comparison performance cost if this attribute is <em class="emphasis">On</em>, 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. </p> <p class="para"> Possible values are: <ul class="simplelist"> <li class="member"><b><tt>Collator::OFF</tt></b>(default)</li> <li class="member"><b><tt>Collator::ON</tt></b></li> <li class="member"><b><tt>Collator::DEFAULT_VALUE</tt></b></li> </ul> </p> </dd> </dt> <dt> <span class="term"> <b><tt>Collator::STRENGTH</tt></b> (<a href="language.types.integer.html" class="type integer">integer</a>) </span> <dd> <p class="para"> 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 <a href="collator.setstrength.html" class="function">collator_set_strength()</a> chapter. </p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -