<?php include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc'; $TOC = array(); $TOC_DEPRECATED = array(); $PARENTS = array(); include_once dirname(__FILE__) ."/toc/class.intlchar.inc"; $setup = array ( 'home' => array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'intlchar.digit.php', 1 => 'IntlChar::digit', 2 => 'Get the decimal digit value of a code point for a given radix', ), 'up' => array ( 0 => 'class.intlchar.php', 1 => 'IntlChar', ), 'prev' => array ( 0 => 'intlchar.chr.php', 1 => 'IntlChar::chr', ), 'next' => array ( 0 => 'intlchar.enumcharnames.php', 1 => 'IntlChar::enumCharNames', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/intl/intlchar/digit.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?> <div id="intlchar.digit" class="refentry"> <div class="refnamediv"> <h1 class="refname">IntlChar::digit</h1> <p class="verinfo">(PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">IntlChar::digit</span> — <span class="dc-title">Get the decimal digit value of a code point for a given radix</span></p> </div> <div class="refsect1 description" id="refsect1-intlchar.digit-description"> <h3 class="title">说明</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>IntlChar::digit</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$codepoint</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$base</code><span class="initializer"> = 10</span></span>): <span class="type"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span>|<span class="type"><a href="language.types.null.php" class="type null">null</a></span></span></div> <p class="para rdfs-comment"> Returns the decimal digit value of the code point in the specified radix. </p> <p class="para"> If the radix is not in the range <code class="literal">2<=radix<=36</code> or if the value of <code class="parameter">codepoint</code> is not a valid digit in the specified radix, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> is returned. A character is a valid digit if at least one of the following is true: <ul class="simplelist"> <li>The character has a decimal digit value. Such characters have the general category "Nd" (decimal digit numbers) and a Numeric_Type of Decimal. In this case the value is the character's decimal digit value.</li> <li>The character is one of the uppercase Latin letters 'A' through 'Z'. In this case the value is c-'A'+10.</li> <li>The character is one of the lowercase Latin letters 'a' through 'z'. In this case the value is ch-'a'+10.</li> <li>Latin letters from both the ASCII range (0061..007A, 0041..005A) as well as from the Fullwidth ASCII range (FF41..FF5A, FF21..FF3A) are recognized.</li> </ul> </p> </div> <div class="refsect1 parameters" id="refsect1-intlchar.digit-parameters"> <h3 class="title">参数</h3> <dl> <dt><code class="parameter">codepoint</code></dt> <dd> <p class="para">The <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> codepoint value (e.g. <code class="literal">0x2603</code> for <em>U+2603 SNOWMAN</em>), or the character encoded as a UTF-8 <span class="type"><a href="language.types.string.php" class="type string">string</a></span> (e.g. <code class="literal">"\u{2603}"</code>)</p> </dd> <dt><code class="parameter">base</code></dt> <dd> <p class="para"> The radix (defaults to <code class="literal">10</code>). </p> </dd> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-intlchar.digit-returnvalues"> <h3 class="title">返回值</h3> <p class="para"> Returns the numeric value represented by the character in the specified radix, or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> if there is no value or if the value exceeds the radix. Returns <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> on failure. </p> <div class="warning"><strong class="warning">警告</strong><p class="simpara">此函数可能返回布尔值 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>,但也可能返回等同于 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> 的非布尔值。请阅读 <a href="language.types.boolean.php" class="link">布尔类型</a>章节以获取更多信息。应使用 <a href="language.operators.comparison.php" class="link">=== 运算符</a>来测试此函数的返回值。</p></div> </div> <div class="refsect1 examples" id="refsect1-intlchar.digit-examples"> <h3 class="title">示例</h3> <div class="example" id="example-2678"> <p><strong>示例 #1 Testing different code points</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">IntlChar</span><span style="color: #007700">::</span><span style="color: #0000BB">digit</span><span style="color: #007700">(</span><span style="color: #DD0000">"0"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">IntlChar</span><span style="color: #007700">::</span><span style="color: #0000BB">digit</span><span style="color: #007700">(</span><span style="color: #DD0000">"3"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">IntlChar</span><span style="color: #007700">::</span><span style="color: #0000BB">digit</span><span style="color: #007700">(</span><span style="color: #DD0000">"A"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">IntlChar</span><span style="color: #007700">::</span><span style="color: #0000BB">digit</span><span style="color: #007700">(</span><span style="color: #DD0000">"A"</span><span style="color: #007700">, </span><span style="color: #0000BB">16</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <div class="example-contents"><p>以上示例会输出:</p></div> <div class="example-contents screen"> <div class="examplescode"><pre class="examplescode">int(0) int(3) bool(false) int(10)</pre> </div> </div> </div> </div> <div class="refsect1 seealso" id="refsect1-intlchar.digit-seealso"> <h3 class="title">参见</h3> <p class="para"> <ul class="simplelist"> <li><span class="function"><a href="intlchar.fordigit.php" class="function" rel="rdfs-seeAlso">IntlChar::forDigit()</a> - Get character representation for a given digit and radix</span></li> <li><span class="function"><a href="intlchar.chardigitvalue.php" class="function" rel="rdfs-seeAlso">IntlChar::charDigitValue()</a> - Get the decimal digit value of a decimal digit character</span></li> <li><span class="function"><a href="intlchar.isdigit.php" class="function" rel="rdfs-seeAlso">IntlChar::isdigit()</a> - Check if code point is a digit character</span></li> <li><strong><code><a href="class.intlchar.php#intlchar.constants.property-numeric-type">IntlChar::PROPERTY_NUMERIC_TYPE</a></code></strong></li> </ul> </p> </div> </div><?php manual_footer($setup); ?>