collator.setstrength.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 263 行

HTML
263
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Set collation strength</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="collator.setattribute.html">Collator::setAttribute</a></div> <div class="next" style="text-align: right; float: right;"><a href="collator.sortwithsortkeys.html">Collator::sortWithSortKeys</a></div> <div class="up"><a href="class.collator.html">Collator</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="collator.setstrength" class="refentry"> <div class="refnamediv">  <h1 class="refname">Collator::setStrength</h1>  <h1 class="refname">collator_set_strength</h1>  <p class="verinfo">(No version information available, might be only in CVS)</p><p class="refpurpose"><span class="refname">Collator::setStrength</span> -- <span class="refname">collator_set_strength</span> &mdash; <span class="dc-title">Set collation strength</span></p> </div> <div class="refsect1 description">  <h3 class="title">Description</h3>  <p class="para">   Object oriented style  </p>  <div class="methodsynopsis dc-description">   <span class="type">bool</span>    <span class="methodname"><b><b>Collator::setStrength</b></b></span>    ( <span class="methodparam"><span class="type">integer</span> <tt class="parameter">$strength</tt></span>   )</div>  <p class="para rdfs-comment">   Procedural style  </p>  <div class="methodsynopsis dc-description">   <span class="type">bool</span>    <span class="methodname"><b><b>collator_set_strength</b></b></span>    ( <span class="methodparam"><span class="type"><a href="class.collator.html" class="type Collator">Collator</a></span> <tt class="parameter">$coll</tt></span>   , <span class="methodparam"><span class="type">integer</span> <tt class="parameter">$strength</tt></span>   )</div>  <p class="para rdfs-comment">   The   <a href="http://www.icu-project.org/" class="link external">&raquo; ICU</a>   Collation Service supports many levels of comparison (named &quot;Levels&quot;, but   also known as &quot;Strengths&quot;). 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.  </p>  <p class="para">   <ol class="orderedlist">    <li class="listitem">     <p class="para">       <em class="emphasis"> Primary Level</em>:      Typically, this is used to denote differences between base characters      (for example, &quot;a&quot; &lt; &quot;b&quot;). It is the strongest difference. For      example, dictionaries are divided into different sections by base      character. This is also called the level1 strength.     </p>    </li>    <li class="listitem">     <p class="para">       <em class="emphasis"> Secondary Level</em>:      Accents in the characters are considered secondary differences (for      example, &quot;as&quot; &lt; &quot;脿s&quot; &lt; &quot;at&quot;). 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.      <blockquote><p><b class="note">Note</b>:                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.       <br />      </p></blockquote>     </p>    </li>    <li class="listitem">     <p class="para">       <em class="emphasis"> Tertiary Level</em>:      Upper and lower case differences in characters are distinguished at      the tertiary level (for example, &quot;ao&quot; &lt; &quot;Ao&quot; &lt; &quot;a貌&quot;). In addition,      a variant of a letter differs from the base form on the tertiary level      (such as &quot;A&quot; and &quot; &quot;). 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.     </p>    </li>    <li class="listitem">     <p class="para">       <em class="emphasis"> Quaternary Level</em>:      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, &quot;ab&quot; &lt; &quot;a-b&quot; &lt; &quot;aB&quot;). 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).     </p>    </li>    <li class="listitem">     <p class="para">       <em class="emphasis"> Identical Level</em>:      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.     </p>    </li>   </ol>  </p>  <p class="para">   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.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">coll</tt></i></span>     <dd>      <p class="para">       <a href="class.collator.html" class="classname">Collator</a> object.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">strength</tt></i></span>     <dd>      <p class="para">Strength to set.</p>      <p class="para">       Possible values are:       <ul class="itemizedlist">        <li class="listitem">         <p class="para">          <b><tt>Collator::PRIMARY</tt></b>         </p>        </li>        <li class="listitem">         <p class="para">          <b><tt>Collator::SECONDARY</tt></b>         </p>        </li>        <li class="listitem">         <p class="para">          <b><tt>Collator::TERTIARY</tt></b>         </p>        </li>        <li class="listitem">         <p class="para">          <b><tt>Collator::QUATERNARY</tt></b>         </p>        </li>        <li class="listitem">         <p class="para">          <b><tt>Collator::IDENTICAL</tt></b>         </p>        </li>        <li class="listitem">         <p class="para">          <b><tt>Collator::DEFAULT</tt></b>         </p>        </li>       </ul>      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   Returns <b><tt>TRUE</tt></b> on success or <b><tt>FALSE</tt></b> on failure.  </p> </div> <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 <b>collator_set_strength()</b> example</b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$arr&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;array(&nbsp;</span><span style="color: #DD0000">'a貌'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Ao'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'ao'&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$coll&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">collator_create</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'en_US'&nbsp;</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Sort&nbsp;array&nbsp;using&nbsp;default&nbsp;strength.<br /></span><span style="color: #0000BB">collator_sort</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$coll</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">);&nbsp;<br /></span><span style="color: #0000BB">var_export</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Sort&nbsp;array&nbsp;using&nbsp;primary&nbsp;strength.<br /></span><span style="color: #0000BB">collator_set_strength</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$coll</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Collator</span><span style="color: #007700">::</span><span style="color: #0000BB">PRIMARY&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">collator_sort</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$coll</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_export</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>    <div class="example-contents"><p>The above example will output:</p></div>    <div class="example-contents"><pre><div class="cdata"><pre>array (  0 =&gt; &#039;ao&#039;,  1 =&gt; &#039;Ao&#039;,  2 =&gt; &#039;a貌&#039;,)array (  0 =&gt; &#039;a貌&#039;,  1 =&gt; &#039;Ao&#039;,  2 =&gt; &#039;ao&#039;,)</pre></div>    </pre></div>   </div>  </p> </div> <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="class.collator.html#intl.collator-constants" class="link"><a href="class.collator.html" class="classname">Collator</a> constants</a></li>    <li class="member"><a href="collator.getstrength.html" class="function" rel="rdfs-seeAlso">collator_get_strength()</a></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="collator.setattribute.html">Collator::setAttribute</a></div> <div class="next" style="text-align: right; float: right;"><a href="collator.sortwithsortkeys.html">Collator::sortWithSortKeys</a></div> <div class="up"><a href="class.collator.html">Collator</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?