<?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-strimwidth.php',
    1 => 'mb_strimwidth',
    2 => '获取按指定宽度截断的字符串',
  ),
  'up' => 
  array (
    0 => 'ref.mbstring.php',
    1 => '多字节字符串 函数',
  ),
  'prev' => 
  array (
    0 => 'function.mb-strcut.php',
    1 => 'mb_strcut',
  ),
  'next' => 
  array (
    0 => 'function.mb-stripos.php',
    1 => 'mb_stripos',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/mbstring/functions/mb-strimwidth.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.mb-strimwidth" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mb_strimwidth</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.6, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mb_strimwidth</span> &mdash; <span class="dc-title">获取按指定宽度截断的字符串</span></p>

 </div>
   
 <div class="refsect1 description" id="refsect1-function.mb-strimwidth-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mb_strimwidth</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"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$width</code></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">$trim_marker</code><span class="initializer"> = &quot;&quot;</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="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">string</code> 截断到指定 <code class="parameter">width</code>。其中半角字符计为
   <code class="literal">1</code>，全角字符计为 <code class="literal">2</code>。有关东亚字符宽度的详细信息，请参阅 <a href="http://www.unicode.org/reports/tr11/" class="link external">&raquo;&nbsp;http://www.unicode.org/reports/tr11/</a>。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mb-strimwidth-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">
       开始位置的偏移。从这些字符数开始的截取字符串。（默认是 0 个字符）
       如果 start 是负数，就是字符串结尾处的字符数。
      </p>
     </dd>
    
    
     <dt><code class="parameter">width</code></dt>
     <dd>
      <p class="para">
       所需修剪的宽度。如果指定负宽度，则从字符串末尾开始计数。
       <blockquote class="note"><p><strong class="note">注意</strong>: 
        <p class="para">
         从 PHP 8.3.0 起，传递负宽度已被弃用。
        </p>
       </p></blockquote>
      </p>
     </dd>
    
    
     <dt><code class="parameter">trim_marker</code></dt>
     <dd>
      <p class="para">
       当字符串被截断的时候，将此字符串添加到截断后的末尾。
      </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-strimwidth-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   截断后的 <span class="type"><a href="language.types.string.php" class="type string">string</a></span>。如果设置了 <code class="parameter">trim_marker</code>，还将结尾处的字符替换为
   <code class="parameter">trim_marker</code> ，并符合 <code class="parameter">width</code> 的宽度。
  </p>
 </div>

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

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.3.0</td>
      <td>
       将负的 <code class="parameter">width</code> 传递给
       <span class="function"><strong>mb_strimwidth()</strong></span> 现已废弃。
      </td>
     </tr>

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

     <tr>
      <td>7.1.0</td>
      <td>
       支持负数的 <code class="parameter">start</code> 和 <code class="parameter">width</code>。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>

 
 <div class="refsect1 examples" id="refsect1-function.mb-strimwidth-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>mb_strimwidth()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">mb_strimwidth</span><span style="color: #007700">(</span><span style="color: #DD0000">"Hello World"</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">10</span><span style="color: #007700">, </span><span style="color: #DD0000">"..."</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// 输出 Hello W...<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mb-strimwidth-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.mb-strwidth.php" class="function" rel="rdfs-seeAlso">mb_strwidth()</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); ?>