<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Get the decimal digit value of a code point for a given radix</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="intlchar.chr.html">IntlChar::chr</a></div> <div class="next" style="text-align: right; float: right;"><a href="intlchar.enumcharnames.html">IntlChar::enumCharNames</a></div> <div class="up"><a href="class.intlchar.html">IntlChar</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="intlchar.digit" class="refentry"> <div class="refnamediv"> <h1 class="refname">IntlChar::digit</h1> <p class="verinfo">(PHP 7)</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">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">int</span> <span class="methodname"><strong>IntlChar::digit</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$codepoint</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$radix</code><span class="initializer"> = 10</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 <em>2<=radix<=36</em> or if the value of <code class="parameter">codepoint</code> is not a valid digit in the specified radix, <strong><code>FALSE</code></strong> is returned. A character is a valid digit if at least one of the following is true: <ul class="simplelist"> <li class="member">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 class="member">The character is one of the uppercase Latin letters 'A' through 'Z'. In this case the value is c-'A'+10.</li> <li class="member">The character is one of the lowercase Latin letters 'a' through 'z'. In this case the value is ch-'a'+10.</li> <li class="member">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">Parameters</h3> <dl> <dt> <code class="parameter">codepoint</code></dt> <dd> <p class="para">The <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span> codepoint value (e.g. <em>0x2603</em> for <em class="emphasis">U+2603 SNOWMAN</em>), or the character encoded as a UTF-8 <span class="type"><a href="language.types.string.html" class="type string">string</a></span> (e.g. <em>"\u{2603}"</em>)</p> </dd> <dt> <code class="parameter">radix</code></dt> <dd> <p class="para"> The radix (defaults to <em>10</em>). </p> </dd> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-intlchar.digit-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the numeric value represented by the character in the specified radix, or <strong><code>FALSE</code></strong> if there is no value or if the value exceeds the radix. </p> <div class="warning"><strong class="warning">Warning</strong><p class="simpara">This function may return Boolean <strong><code>FALSE</code></strong>, but may also return a non-Boolean value which evaluates to <strong><code>FALSE</code></strong>. Please read the section on <a href="language.types.boolean.html" class="link">Booleans</a> for more information. Use <a href="language.operators.comparison.html" class="link">the === operator</a> for testing the return value of this function.</p></div> </div> <div class="refsect1 examples" id="refsect1-intlchar.digit-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-3200"> <p><strong>Example #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>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> 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">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><span class="function"><a href="intlchar.fordigit.html" class="function" rel="rdfs-seeAlso">IntlChar::forDigit()</a> - Get character representation for a given digit and radix</span></li> <li class="member"><span class="function"><a href="intlchar.chardigitvalue.html" class="function" rel="rdfs-seeAlso">IntlChar::charDigitValue()</a> - Get the decimal digit value of a decimal digit character</span></li> <li class="member"><span class="function"><a href="intlchar.isdigit.html" class="function" rel="rdfs-seeAlso">IntlChar::isdigit()</a> - Check if code point is a digit character</span></li> <li class="member"><strong><code>IntlChar::PROPERTY_NUMERIC_TYPE</code></strong></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="intlchar.chr.html">IntlChar::chr</a></div> <div class="next" style="text-align: right; float: right;"><a href="intlchar.enumcharnames.html">IntlChar::enumCharNames</a></div> <div class="up"><a href="class.intlchar.html">IntlChar</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>