uTools-Manuals/docs/php/htmlspecialchars_decode.html
2019-04-08 23:22:26 +08:00

204 lines
7.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>将特殊的 HTML 实体转换回普通字符</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><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)</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">string</span> <code class="parameter">$string</code></span>
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = ENT_COMPAT | ENT_HTML401</span></span>
] ) : <span class="type">string</span></div>
<p class="para rdfs-comment">
此函数的作用和 <span class="function"><a href="htmlspecialchars.html" class="function">htmlspecialchars()</a></span> 刚好相反。它将特殊的HTML实体转换回普通字符。
</p>
<p class="para">
被转换的实体有: <em>&amp;amp;</em>
<em>&amp;quot;</em> (没有设置<strong><code>ENT_NOQUOTES</code></strong> 时),
<em>&amp;#039;</em> (设置了 <strong><code>ENT_QUOTES</code></strong> 时),
<em>&amp;lt;</em> 以及<em>&amp;gt;</em>
</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">
用下列标记中的一个或多个作为一个位掩码,来指定如何处理引号和使用哪种文档类型。默认为 <em>ENT_COMPAT | ENT_HTML401</em>
<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>ENT_COMPAT</code></strong></td>
<td>转换双引号,不转换单引号。</td>
</tr>
<tr>
<td><strong><code>ENT_QUOTES</code></strong></td>
<td>单引号和双引号都转换。</td>
</tr>
<tr>
<td><strong><code>ENT_NOQUOTES</code></strong></td>
<td>单引号和双引号都不转换。</td>
</tr>
<tr>
<td><strong><code>ENT_HTML401</code></strong></td>
<td>
作为HTML 4.01编码处理。
</td>
</tr>
<tr>
<td><strong><code>ENT_XML1</code></strong></td>
<td>
作为XML 1编码处理。
</td>
</tr>
<tr>
<td><strong><code>ENT_XHTML</code></strong></td>
<td>
作为XHTML编码处理。
</td>
</tr>
<tr>
<td><strong><code>ENT_HTML5</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>
<p class="para">
<table class="doctable informaltable">
<thead>
<tr>
<th>版本</th>
<th>说明</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td>5.4.0</td>
<td>
增加了 <strong><code>ENT_HTML401</code></strong><strong><code>ENT_XML1</code></strong>
<strong><code>ENT_XHTML</code></strong><strong><code>ENT_HTML5</code></strong> 等常量。
</td>
</tr>
</tbody>
</table>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.htmlspecialchars-decode-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-5913">
<p><strong>Example #1 一个 <span class="function"><strong>htmlspecialchars_decode()</strong></span> 的例子</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$str&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"&lt;p&gt;this&nbsp;-&amp;gt;&nbsp;&amp;quot;&lt;/p&gt;\n"</span><span style="color: #007700">;<br /><br />echo&nbsp;</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">//&nbsp;注意,这里的引号不会被转换<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">htmlspecialchars_decode</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">ENT_NOQUOTES</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程会输出:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
&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 class="member"><span class="function"><a href="htmlspecialchars.html" class="function" rel="rdfs-seeAlso">htmlspecialchars()</a> - 将特殊字符转换为 HTML 实体</span></li>
<li class="member"><span class="function"><a href="html_entity_decode.html" class="function" rel="rdfs-seeAlso">html_entity_decode()</a> - Convert HTML entities to their corresponding characters</span></li>
<li class="member"><span class="function"><a href="get_html_translation_table.html" class="function" rel="rdfs-seeAlso">get_html_translation_table()</a> - 返回使用 htmlspecialchars 和 htmlentities 后的转换表</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>