1
0
mirror of https://github.com/php/doc-ja.git synced 2026-03-27 16:42:17 +01:00
Files
archived-doc-ja/reference/strings/functions/html-entity-decode.xml
TAKAGI Masahiro a3a18f53fa sync with en.
git-svn-id: https://svn.php.net/repository/phpdoc/ja/trunk@326302 c90b9560-bf6c-de11-be94-00142212c4b1
2012-06-23 03:06:20 +00:00

234 lines
7.3 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: f5413e36e958a847f42fc24014fb2eae302f2db1 Maintainer: takagi Status: ready -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.html-entity-decode">
<refnamediv>
<refname>html_entity_decode</refname>
<refpurpose>HTML エンティティを適切な文字に変換する</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>html_entity_decode</methodname>
<methodparam><type>string</type><parameter>string</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>ENT_COMPAT | ENT_HTML401</initializer></methodparam>
<methodparam choice="opt"><type>string</type><parameter>encoding</parameter><initializer>'UTF-8'</initializer></methodparam>
</methodsynopsis>
<para>
<function>html_entity_decode</function>
<function>htmlentities</function> の反対で、<parameter>string</parameter>
にあるすべての HTML エンティティを適切な文字に変換します。
</para>
<para>
厳密に言うと、この関数は次の二つの条件を満たすすべての (数値エンティティを含む)
エンティティをデコードします。それ以外のエンティティは、何も変換しません。
1) 選択したドキュメントタイプで必然的に有効になるもの。つまり
XML の場合には、DTD で定義されている名前付きエンティティはデコードしません。
2) 選択したエンコーディングに関連づけられている符号化文字集合に含まれる文字で、
選択したドキュメントタイプで許可されているもの。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>string</parameter></term>
<listitem>
<para>
入力文字列。
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>flags</parameter></term>
<listitem>
<para>
以下のフラグのビットマスクによる組み合わせで、クォートの扱いやドキュメントの形式を指定します。
デフォルトは <literal>ENT_COMPAT | ENT_HTML401</literal> です。
<table>
<title>使用可能な <parameter>flags</parameter> 定数</title>
<tgroup cols="2">
<thead>
<row>
<entry>定数名</entry>
<entry>説明</entry>
</row>
</thead>
<tbody>
<row>
<entry><constant>ENT_COMPAT</constant></entry>
<entry>ダブルクォートを変換し、シングルクォートはそのままにします。</entry>
</row>
<row>
<entry><constant>ENT_QUOTES</constant></entry>
<entry>ダブルクォート、シングルクォートの両方を変換します。</entry>
</row>
<row>
<entry><constant>ENT_NOQUOTES</constant></entry>
<entry>ダブルクォート、シングルクォートの両方とも変換しません。</entry>
</row>
<row>
<entry><constant>ENT_HTML401</constant></entry>
<entry>
コードを HTML 4.01 として処理します。
</entry>
</row>
<row>
<entry><constant>ENT_XML1</constant></entry>
<entry>
コードを XML 1 として処理します。
</entry>
</row>
<row>
<entry><constant>ENT_XHTML</constant></entry>
<entry>
コードを XHTML として処理します。
</entry>
</row>
<row>
<entry><constant>ENT_HTML5</constant></entry>
<entry>
コードを HTML 5 として処理します。
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>encoding</parameter></term>
<listitem>
<para>
使用するエンコーディング。省略した場合のデフォルト値は、
PHP 5.4.0 より前のバージョンでは ISO-8859-1、そして
PHP 5.4.0 以降では UTF-8 となります。
</para>
&reference.strings.charsets;
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
デコードされた文字列を返します。
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>5.3.3</entry>
<entry>
デフォルトのエンコーディングが ISO-8859-1 から UTF-8 に変わりました。
</entry>
</row>
<row>
<entry>5.4.0</entry>
<entry>
定数 <constant>ENT_HTML401</constant><constant>ENT_XML1</constant>
<constant>ENT_XHTML</constant> および <constant>ENT_HTML5</constant> が追加されました。
</entry>
</row>
<row>
<entry>5.0.0</entry>
<entry>
マルチバイトエンコーディングをサポートするようになりました。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>HTML エンティティのデコード</title>
<programlisting role="php">
<![CDATA[
<?php
$orig = "I'll \"walk\" the <b>dog</b> now";
$a = htmlentities($orig);
$b = html_entity_decode($a);
echo $a; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now
echo $b; // I'll "walk" the <b>dog</b> now
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>
<para>
trim(html_entity_decode('&amp;nbsp;')); の結果が空の文字列に
ならないことを疑問に思う人もいるでしょう。なぜそうなるのかというと、
デフォルトのエンコーディング ISO-8859-1 では
'&amp;nbsp;' エンティティが ASCII コード 32 (これは
<function>trim</function> で取り除かれる) ではなく
ASCII コード 160 (0xa0) に変換されるからです。
</para>
</note>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>htmlentities</function></member>
<member><function>htmlspecialchars</function></member>
<member><function>get_html_translation_table</function></member>
<member><function>urldecode</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->