<?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.get-html-translation-table.php',
    1 => 'get_html_translation_table',
    2 => '返回使用 htmlspecialchars 和 htmlentities 后的转换表',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => '字符串 函数',
  ),
  'prev' => 
  array (
    0 => 'function.fprintf.php',
    1 => 'fprintf',
  ),
  'next' => 
  array (
    0 => 'function.hebrev.php',
    1 => 'hebrev',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/strings/functions/get-html-translation-table.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.get-html-translation-table" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">get_html_translation_table</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">get_html_translation_table</span> &mdash; <span class="dc-title">返回使用 <span class="function"><a href="function.htmlspecialchars.php" class="function">htmlspecialchars()</a></span> 和 <span class="function"><a href="function.htmlentities.php" class="function">htmlentities()</a></span> 后的转换表</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.get-html-translation-table-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>get_html_translation_table</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$table</code><span class="initializer"> = <strong><code><a href="string.constants.php#constant.html-specialchars">HTML_SPECIALCHARS</a></code></strong></span></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="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$encoding</code><span class="initializer"> = &quot;UTF-8&quot;</span></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>get_html_translation_table()</strong></span> 将返回 <span class="function"><a href="function.htmlspecialchars.php" class="function">htmlspecialchars()</a></span> 和
   <span class="function"><a href="function.htmlentities.php" class="function">htmlentities()</a></span> 处理后的转换表。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    特殊字符可以使用多种转换方式。 例如：
    <code class="literal">&quot;</code> 可以被转换成 <code class="literal">&amp;quot;</code>,
    <code class="literal">&amp;#34;</code> 或者 <code class="literal">&amp;#x22</code>.
    <span class="function"><strong>get_html_translation_table()</strong></span> 返回其中最常用的。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.get-html-translation-table-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">table</code></dt>
     <dd>
      <p class="para">
       有两个新的常量 (<strong><code><a href="string.constants.php#constant.html-entities">HTML_ENTITIES</a></code></strong>,
       <strong><code><a href="string.constants.php#constant.html-specialchars">HTML_SPECIALCHARS</a></code></strong>) 允许你指定你想要的表。
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       A bitmask of one or more of the following flags, which specify which quotes the
       table will contain as well as which document type the table is for. The default is
       <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>
            Replace invalid code unit sequences with a Unicode Replacement Character
            U+FFFD (UTF-8) or &amp;#xFFFD; (otherwise) instead of returning an empty string.
           </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>
    
    
     <dt><code class="parameter">encoding</code></dt>
     <dd>
      <p class="para">
       要使用的编码。如果省略，则此参数的默认值是 UTF-8。
      </p>
      


<p class="para">
 支持以下字符集：
 <table class="doctable table">
  <caption><strong>支持的字符集列表</strong></caption>
  
   <thead>
    <tr>
     <th>字符集</th>
     <th>别名</th>
     <th>描述</th>
    </tr>

   </thead>

   <tbody class="tbody">
    <tr>
     <td>ISO-8859-1</td>
     <td>ISO8859-1</td>
     <td>
      西欧，Latin-1
     </td>
    </tr>

    <tr>
     <td>ISO-8859-5</td>
     <td>ISO8859-5</td>
     <td>
      Little used cyrillic charset (Latin/Cyrillic).
     </td>
    </tr>

    <tr>
     <td>ISO-8859-15</td>
     <td>ISO8859-15</td>
     <td>
      西欧，Latin-9。增加欧元符号，法语和芬兰语字母在 Latin-1(ISO-8859-1) 中缺失。
     </td>
    </tr>

    <tr>
     <td>UTF-8</td>
     <td class="empty">&nbsp;</td>
     <td>
      ASCII 兼容的多字节 8 位 Unicode。
     </td>
    </tr>

    <tr>
     <td>cp866</td>
     <td>ibm866, 866</td>
     <td>
      DOS 特有的西里尔编码。本字符集在 4.3.2 版本中得到支持。
     </td>
    </tr>

    <tr>
     <td>cp1251</td>
     <td>Windows-1251, win-1251, 1251</td>
     <td>
      Windows 特有的西里尔编码。本字符集在 4.3.2 版本中得到支持。
     </td>
    </tr>

    <tr>
     <td>cp1252</td>
     <td>Windows-1252, 1252</td>
     <td>
      Windows 特有的西欧编码。
     </td>
    </tr>

    <tr>
     <td>KOI8-R</td>
     <td>koi8-ru, koi8r</td>
     <td>
      俄语。本字符集在 4.3.2 版本中得到支持。
     </td>
    </tr>

    <tr>
     <td>BIG5</td>
     <td>950</td>
     <td>
      繁体中文，主要用于中国台湾省。
     </td>
    </tr>

    <tr>
     <td>GB2312</td>
     <td>936</td>
     <td>
      简体中文，中国国家标准字符集。
     </td>
    </tr>

    <tr>
     <td>BIG5-HKSCS</td>
     <td class="empty">&nbsp;</td>
     <td>
      繁体中文，附带香港扩展的 Big5 字符集。
     </td>
    </tr>

    <tr>
     <td>Shift_JIS</td>
     <td>SJIS, 932</td>
     <td>
      日语
     </td>
    </tr>

    <tr>
     <td>EUC-JP</td>
     <td>EUCJP</td>
     <td>
      日语
     </td>
    </tr>

    <tr>
     <td>MacRoman</td>
     <td class="empty">&nbsp;</td>
     <td>
      Mac OS 使用的字符串。
     </td>
    </tr>

    <tr>
     <td><code class="literal">&#039;&#039;</code></td>
     <td class="empty">&nbsp;</td>
     <td>
      An empty string activates detection from script encoding (Zend multibyte),
      <a href="ini.core.php#ini.default-charset" class="link">default_charset</a> and current
      locale (see <span class="function"><a href="function.nl-langinfo.php" class="function">nl_langinfo()</a></span> and
      <span class="function"><a href="function.setlocale.php" class="function">setlocale()</a></span>), in this order. Not recommended.
     </td>
    </tr>

   </tbody>
  
 </table>

 <blockquote class="note"><p><strong class="note">注意</strong>: 
  <span class="simpara">
   其他字符集没有认可。将会使用默认编码并抛出异常。
  </span>
 </p></blockquote>
</p>


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


 <div class="refsect1 returnvalues" id="refsect1-function.get-html-translation-table-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   将转换表作为数组返回，原始字符为键，实体为值。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.get-html-translation-table-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.get-html-translation-table-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 转换表示例</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">get_html_translation_table</span><span style="color: #007700">(</span><span style="color: #0000BB">HTML_ENTITIES</span><span style="color: #007700">, </span><span style="color: #0000BB">ENT_QUOTES </span><span style="color: #007700">| </span><span style="color: #0000BB">ENT_HTML5</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">array(1510) {
  [&quot;
&quot;]=&gt;
  string(9) &quot;&amp;NewLine;&quot;
  [&quot;!&quot;]=&gt;
  string(6) &quot;&amp;excl;&quot;
  [&quot;&quot;&quot;]=&gt;
  string(6) &quot;&amp;quot;&quot;
  [&quot;#&quot;]=&gt;
  string(5) &quot;&amp;num;&quot;
  [&quot;$&quot;]=&gt;
  string(8) &quot;&amp;dollar;&quot;
  [&quot;%&quot;]=&gt;
  string(8) &quot;&amp;percnt;&quot;
  [&quot;&amp;&quot;]=&gt;
  string(5) &quot;&amp;amp;&quot;
  [&quot;&#039;&quot;]=&gt;
  string(6) &quot;&amp;apos;&quot;
  // ...
}</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.get-html-translation-table-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.htmlentities.php" class="function" rel="rdfs-seeAlso">htmlentities()</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>
   </ul>
  </p>
 </div>


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