<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.htmlspecialchars-decode.php',
    1 => 'htmlspecialchars_decode',
    2 => '将特殊的 HTML 实体转换回普通字符',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => '字符串 函数',
  ),
  'prev' => 
  array (
    0 => 'function.htmlspecialchars.php',
    1 => 'htmlspecialchars',
  ),
  'next' => 
  array (
    0 => 'function.implode.php',
    1 => 'implode',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/strings/functions/htmlspecialchars-decode.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.htmlspecialchars-decode" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">htmlspecialchars_decode</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">htmlspecialchars_decode</span> &mdash; <span class="dc-title">
   将特殊的 HTML 实体转换回普通字符
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.htmlspecialchars-decode-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>htmlspecialchars_decode</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401</span></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>


  <p class="para rdfs-comment">
   此函数的作用和 <span class="function"><a href="function.htmlspecialchars.php" class="function">htmlspecialchars()</a></span> 刚好相反。它将特殊的HTML实体转换回普通字符。
  </p>
  <p class="para">
   被转换的实体有： <code class="literal">&amp;amp;</code>，
   <code class="literal">&amp;quot;</code> （没有设置<strong><code><a href="string.constants.php#constant.ent-noquotes">ENT_NOQUOTES</a></code></strong> 时）,
   <code class="literal">&amp;#039;</code> （设置了 <strong><code><a href="string.constants.php#constant.ent-quotes">ENT_QUOTES</a></code></strong> 时），
   <code class="literal">&amp;lt;</code> 以及<code class="literal">&amp;gt;</code>。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.htmlspecialchars-decode-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       要解码的字符串
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       用下列标记中的一个或多个作为一个位掩码，来指定如何处理引号和使用哪种文档类型。默认为 <code class="literal">ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401</code>。
       <table class="doctable table">
        <caption><strong>有效的 <code class="parameter">flags</code> 常量</strong></caption>
        
         <thead>
          <tr>
           <th>常量名</th>
           <th>说明</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-compat">ENT_COMPAT</a></code></strong></td>
           <td>转换双引号，不转换单引号。</td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-quotes">ENT_QUOTES</a></code></strong></td>
           <td>单引号和双引号都转换。</td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-noquotes">ENT_NOQUOTES</a></code></strong></td>
           <td>单引号和双引号都不转换。</td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-substitute">ENT_SUBSTITUTE</a></code></strong></td>
           <td>
            使用 Unicode 替换符 U+FFFD (UTF-8) 或 &amp;#xFFFD 替换无效的码区序列（code unit sequence）。而不是返回空字符串。
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-html401">ENT_HTML401</a></code></strong></td>
           <td>
            作为HTML 4.01编码处理。
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-xml1">ENT_XML1</a></code></strong></td>
           <td>
            作为XML 1编码处理。
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-xhtml">ENT_XHTML</a></code></strong></td>
           <td>
            作为XHTML编码处理。
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="string.constants.php#constant.ent-html5">ENT_HTML5</a></code></strong></td>
           <td>
            作为HTML 5编码处理。
           </td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.htmlspecialchars-decode-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回解码后的字符串。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.htmlspecialchars-decode-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>
       <code class="parameter">flags</code> 从 <strong><code><a href="string.constants.php#constant.ent-compat">ENT_COMPAT</a></code></strong> 变更为<strong><code><a href="string.constants.php#constant.ent-quotes">ENT_QUOTES</a></code></strong>
       | <strong><code><a href="string.constants.php#constant.ent-substitute">ENT_SUBSTITUTE</a></code></strong> | <strong><code><a href="string.constants.php#constant.ent-html401">ENT_HTML401</a></code></strong>。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.htmlspecialchars-decode-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>htmlspecialchars_decode()</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 />$str </span><span style="color: #007700">= </span><span style="color: #DD0000">"&lt;p&gt;this -&amp;gt; &amp;quot;&lt;/p&gt;\n"</span><span style="color: #007700">;<br /><br />echo </span><span style="color: #0000BB">htmlspecialchars_decode</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// 注意，这里的引号不会被转换<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">htmlspecialchars_decode</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">, </span><span style="color: #0000BB">ENT_NOQUOTES</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>以上示例会输出：</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">&lt;p&gt;this -&gt; &quot;&lt;/p&gt;
&lt;p&gt;this -&gt; &amp;quot;&lt;/p&gt;</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.htmlspecialchars-decode-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.htmlspecialchars.php" class="function" rel="rdfs-seeAlso">htmlspecialchars()</a> - 将特殊字符转换为 HTML 实体</span></li>
    <li><span class="function"><a href="function.html-entity-decode.php" class="function" rel="rdfs-seeAlso">html_entity_decode()</a> - Convert HTML entities to their corresponding characters</span></li>
    <li><span class="function"><a href="function.get-html-translation-table.php" class="function" rel="rdfs-seeAlso">get_html_translation_table()</a> - 返回使用 htmlspecialchars 和 htmlentities 后的转换表</span></li>
   </ul>
  </p>
 </div>

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