<?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-check-encoding.php',
    1 => 'mb_check_encoding',
    2 => '检查字符串在指定的编码里是否有效',
  ),
  'up' => 
  array (
    0 => 'ref.mbstring.php',
    1 => '多字节字符串 函数',
  ),
  'prev' => 
  array (
    0 => 'ref.mbstring.php',
    1 => '多字节字符串 函数',
  ),
  'next' => 
  array (
    0 => 'function.mb-chr.php',
    1 => 'mb_chr',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/mbstring/functions/mb-check-encoding.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.mb-check-encoding" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mb_check_encoding</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.4.3, PHP 5 &gt;= 5.1.3, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mb_check_encoding</span> &mdash; <span class="dc-title">检查字符串在指定的编码里是否有效</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.mb-check-encoding-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mb_check_encoding</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.null.php" class="type null">null</a></span></span> <code class="parameter">$value</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>, <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>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   检查指定字节流在指定编码中是否有效。如果 <code class="parameter">value</code> 是 <span class="type"><a href="language.types.array.php" class="type array">array</a></span> 类型，则递归验证所有键和值。它能有效避免所谓的“无效编码攻击（Invalid Encoding Attack）”。
  </p>
  <p class="para">
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mb-check-encoding-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       要检查的字节流或 <span class="type"><a href="language.types.array.php" class="type array">array</a></span>。如果省略了这个参数，此函数会检查所有来自最初请求所有的输入。
      </p>

      <div class="warning"><strong class="warning">警告</strong>
        <p class="para">
         自 PHP 8.1.0 起，禁止省略此参数或传递 <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>。
        </p>
      </div>
     </dd>
    
    
     <dt><code class="parameter">encoding</code></dt>
     <dd>
      <p class="para">
       期望的编码。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mb-check-encoding-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>， 或者在失败时返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。
  </p>
 </div>


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

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.1.0</td>
      <td>
       弃用使用 <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> 作为 <code class="parameter">value</code> 或不带参数调用此函数。
      </td>
     </tr>

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

     <tr>
      <td>7.2.0</td>
      <td>
       此函数现在也接受 <span class="type"><a href="language.types.array.php" class="type array">array</a></span> 作为 <code class="parameter">value</code>。之前仅支持 <span class="type"><a href="language.types.string.php" class="type string">string</a></span>。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


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