mirror of
https://github.com/php/doc-ja.git
synced 2026-03-30 19:12:28 +02:00
git-svn-id: https://svn.php.net/repository/phpdoc/ja/trunk@198603 c90b9560-bf6c-de11-be94-00142212c4b1
144 lines
4.8 KiB
XML
144 lines
4.8 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision: 1.1 $ -->
|
|
<!-- EN-Revision: 1.11 Maintainer: takagi Status: ready -->
|
|
<refentry id="function.html-entity-decode">
|
|
<refnamediv>
|
|
<refname>html_entity_decode</refname>
|
|
<refpurpose>
|
|
HTML エンティティを適切な文字に変換する
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>説明</title>
|
|
<methodsynopsis>
|
|
<type>string</type><methodname>html_entity_decode</methodname>
|
|
<methodparam><type>string</type><parameter>string</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>quote_style</parameter></methodparam>
|
|
<methodparam choice="opt"><type>string</type><parameter>charset</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>html_entity_decode</function> は
|
|
<function>htmlentities</function> の反対で、<parameter>string</parameter>
|
|
にあるすべての HTML エンティティを適切な文字に変換します。
|
|
</para>
|
|
<para>
|
|
オプションの 2 番目のパラメータ <parameter>quote_style</parameter>
|
|
は 'シングルクォート' および "ダブルクォート" をどのように扱うかを
|
|
指定します。以下の 3 つの定数のうちのひとつを指定でき、デフォルトは
|
|
<constant>ENT_COMPAT</constant> です。
|
|
<table>
|
|
<title>使用可能な <parameter>quote_style</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>
|
|
</tbody>
|
|
</tgroup>
|
|
</table>
|
|
</para>
|
|
<para>
|
|
オプションの 3 番目のパラメータ <parameter>charset</parameter> の
|
|
デフォルトは ISO-8859-1 です。これは変換に使用する文字セットを指定します。
|
|
</para>
|
|
&reference.strings.charsets;
|
|
<para>
|
|
<note>
|
|
<para>
|
|
この関数は、PHP < 5 ではマルチバイト文字セットをサポートしません。
|
|
</para>
|
|
</note>
|
|
<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 "walk" the <b>dog</b> now
|
|
|
|
echo $b; // I'll "walk" the <b>dog</b> now
|
|
|
|
|
|
// PHP 4.3.0 より前のバージョンでは、このようにします
|
|
function unhtmlentities($string)
|
|
{
|
|
// 数値エンティティの置換
|
|
$string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
|
|
$string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string);
|
|
// 文字エンティティの置換
|
|
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
|
|
$trans_tbl = array_flip($trans_tbl);
|
|
return strtr($string, $trans_tbl);
|
|
}
|
|
|
|
$c = unhtmlentities($a);
|
|
|
|
echo $c; // I'll "walk" the <b>dog</b> now
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<note>
|
|
<para>
|
|
trim(html_entity_decode('&nbsp;')); の結果が空の文字列に
|
|
ならないことを疑問に思う人もいるでしょう。なぜそうなるのかというと、
|
|
デフォルトの文字セット ISO-8859-1 では
|
|
'&nbsp;' エンティティが ASCII コード 32 (これは
|
|
<function>trim</function> で取り除かれる) ではなく
|
|
ASCII コード 160 (0xa0) に変換されるからです。
|
|
</para>
|
|
</note>
|
|
</para>
|
|
<para>
|
|
<function>htmlentities</function>、
|
|
<function>htmlspecialchars</function>、
|
|
<function>get_html_translation_table</function> および
|
|
<function>urldecode</function> も参照ください。
|
|
</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:"../../../../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
|
|
-->
|