.Water-Sunlight
.サイトメニュー
.検索
.オンライン状況
登録ユーザ: 0
ゲスト: 8
.
<< Prev
URL関数
« INDEX »
PHP WEB要素編
Next >>
GET/POST
作成日:2006/05/18

2A.4 HTML関連関数

構文説明
string htmlspecialchars
(string string,
[,int quote_style]
[,string charset]] )

string
htmlspecialchars_decode
( string string
[,int quote_style] )

htmlspecialchars() は文字列 string の中に含まれる HTMLの特殊文字を文字エンティティ(実体参照)に変換して返します。 変換対象となる文字は以下の通りです。

  • &   &amp;
  • <   &lt;
  • >   &gt;
  • "   &quot; ※引数quote_styleにより異なる(以下参照)
  • '   &#039; ※引数quote_styleにより異なる(以下参照)

オプション引数 quote_style は、 シングル及びダブルクオートの変換について指定します。 quote_style には以下の値が指定できます。

  • ENT_COMPAT ---- ダブルクオートは変換しシングルクオートは変換しません(デフォルト)
  • ENT_QUOTES ---- ダブルクオートシングルクオート共に変換します
  • ENT_NOQUOTES -- ダブルクオートシングルクオート共にしません

オプション引数 charsetは、変換に使用される文字セットを指定します。デフォルトの文字セットは、'ISO-8859-1'です。 指定できる文字セットは「PHPマニュアル htmlspecialchars」 を参照して下さい。

全てのHTML文字エンティティに変換する場合は、htmlentities() を使用し てください。
htmlspecialchars_decode() は htmlspecialchars() の逆変換です。

用例:
echo htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
string htmlentities
( string string,
[,int quote_style,
[,string charset]] )

string html_entity_decode
( string string
[,int quote_style
[,string charset]] )

htmlentities() は文字列 string の中に含まれる HTML文字エンティティ(実体参照)に変換可能な全ての文字を変換して返します。 htmlentities() はhtmlspecialchars() で変換される特定の文字( & < > " ' ) に加えて &nbsp;(Latin-1コードの0xA0以降)から始まる 文字エンティティも変換の対象になります。

オプション引数quote_styleとcharsetは、htmlspecialchars() と同じです。
html_entity_decode() は htmlentities() の逆変換です。(PHP4.30以降で使用できます)

array 
get_html_translation_table
( int table
[,int quote_style] )

get_html_translation_table() は、htmlspecialchars() および htmlentities() で内部的に使用される変換テーブルを配列で返します。 引数 table には次の値を指定します。

  • HTML_SPECIALCHARS -- htmlspecialchars()で使用する変換テーブルを返します
  • HTML_ENTITIES ------ htmlentities()で使用する変換テーブルを返すします

オプション引数 quote_style は htmlspecialchars() と同じです。

用例:
$trans   = get_html_translation_table(HTML_ENTITIES);
$encoded = strtr($str, $trans); // htmlentities()と同じ

$edcoded = strtr($str, array_flip($trans)); // 逆変換(デコード)
string nl2br
( string string )

string に含まれるすべての改行文字の前に '<br />' を挿入して返します。


ISO-8859-1
規格 ISO-8859中の1番目の仕様です。 この文字セットは、一般に「Latin-1」と呼ばれる西欧言語に対応するラテン文字セットを定義しています。

.