<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.mbstring.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.mb-strcut.php',
    1 => 'mb_strcut',
    2 => '获取字符的一部分',
  ),
  'up' => 
  array (
    0 => 'ref.mbstring.php',
    1 => '多字节字符串 函数',
  ),
  'prev' => 
  array (
    0 => 'function.mb-str-split.php',
    1 => 'mb_str_split',
  ),
  'next' => 
  array (
    0 => 'function.mb-strimwidth.php',
    1 => 'mb_strimwidth',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/mbstring/functions/mb-strcut.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.mb-strcut" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mb_strcut</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.6, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mb_strcut</span> &mdash; <span class="dc-title">获取字符的一部分</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.mb-strcut-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mb_strcut</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$start</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$length</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$encoding</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>mb_strcut()</strong></span> 和 <span class="function"><a href="function.mb-substr.php" class="function">mb_substr()</a></span> 类似，都是从字符串中提取子字符串，但是按字节数来执行，而不是字符个数。
   如果截断位置位于多字节字符两个字节的中间，将于该字符的第一个字节开始执行。
   这也是和 <span class="function"><a href="function.substr.php" class="function">substr()</a></span> 函数的不同之处，后者简单地将字符串在字节之间截断，这将导致一个畸形的字节序列。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mb-strcut-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       要截断的 <span class="type"><a href="language.types.string.php" class="type string">string</a></span>。
      </p>
     </dd>
    
    
     <dt><code class="parameter">start</code></dt>
     <dd>
      <p class="para">
        如果 <code class="parameter">start</code> 不是负数，返回的字符串会从 <code class="parameter">string</code> 的第 <code class="parameter">start</code> <em>字节</em>位置开始，从 0 开始计数。举个例子，字符串 &#039;<code class="literal">abcdef</code>&#039;，字节位置 <code class="literal">0</code> 的字符是 &#039;<code class="literal">a</code>&#039;，字节位置 <code class="literal">2</code> 的字符是
       &#039;<code class="literal">c</code>&#039;，以此类推。
      </p>
      <p class="para">
       如果 <code class="parameter">start</code> 是负数，返回的字符串是从 <code class="parameter">string</code> 末尾倒数第 <code class="parameter">start</code>
       个字节开始的。但是，如果负 <code class="parameter">start</code> 大于字符串的长度，则返回的部分将从 <code class="parameter">string</code> 的开头开始。
      </p>
     </dd>
    
    
     <dt><code class="parameter">length</code></dt>
     <dd>
      <p class="para">
       <em>字节</em>长度。如果省略或传递 <code class="literal">NULL</code>，则将所有字节提取到字符串的末尾。
      </p>
      <p class="para">
       如果 <code class="parameter">length</code> 为负数，则返回的字符串将在从 <code class="parameter">string</code> 末尾倒数的第 <code class="parameter">length</code>
       个字节处结束。但是，如果负 <code class="parameter">length</code> 大于 <code class="parameter">start</code> 位置之后的字符数，则返回空字符串。
      </p>
     </dd>
    
    
     <dt><code class="parameter">encoding</code></dt>
     <dd>
      <p class="para"><code class="parameter">encoding</code>
参数为字符编码。如果省略或是 <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>，则使用内部字符编码。</p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mb-strcut-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <span class="function"><strong>mb_strcut()</strong></span> 根据 <code class="parameter">start</code> 和 <code class="parameter">length</code> 参数返回 <code class="parameter">string</code> 的一部分。
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-function.mb-strcut-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
  <td>8.0.0</td>
  <td>
   现在 <code class="parameter">encoding</code> 可以为 null。
  </td>
 </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 seealso" id="refsect1-function.mb-strcut-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.mb-substr.php" class="function" rel="rdfs-seeAlso">mb_substr()</a> - 获取部分字符串</span></li>
    <li><span class="function"><a href="function.mb-internal-encoding.php" class="function" rel="rdfs-seeAlso">mb_internal_encoding()</a> - 设置/获取内部字符编码</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>