SEARCH

このマニュアルはSmartyのものです。セキュリティなどの問題でRCMSでは利用できないものもありますので、ご注意ください。
escape

escape

escape は変数のエンコードやエスケープを行います。 たとえば htmlurlシングルクォートhexhexentityjavascript および mail などに対する処理を行います。 デフォルトでは html 用の処理をします。

パラメータの位置必須有効な値デフォルト概要
1stringNohtml, htmlall, url, urlpathinfo, quotes, hex, hexentity, javascript, mail html使用するエスケープフォーマット
2stringNoISO-8859-1, UTF-8 および htmlentities() がサポートする任意の文字セット ISO-8859-1htmlentities() へ渡す文字セットのエンコーディング

例 5-10. escape

<?php

$smarty
->assign('articleTitle',
                
"'Stiff Opposition Expected to Casketless Funeral Plan'"
                
);
$smarty->assign('EmailAddress','smarty@example.com');

?>

escape を使用するテンプレートの後に、その出力結果を続けています。

{$articleTitle}
'Stiff Opposition Expected to Casketless Funeral Plan'

{$articleTitle|escape}
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;

{$articleTitle|escape:'html'}    {* & " ' < > をエスケープします *}
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;

{$articleTitle|escape:'htmlall'} {* 全ての html エンティティをエスケープします *}
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;

<a href="?title={$articleTitle|escape:'url'}"&#62;click here&#60;/a&#62;
&#60;a href="?title=%27Stiff+Opposition+Expected+to+Casketless+Funeral+Plan%27">click here</a>

{$articleTitle|escape:'quotes'}
\'Stiff Opposition Expected to Casketless Funeral Plan\'

<a href="mailto:{$EmailAddress|escape:"hex"}"&#62;{$EmailAddress|escape:"hexentity"}</a>
{$EmailAddress|escape:'mail'}    {* email をテキストに変換します *}
<a href="mailto:%62%6f%..snip..%65%74">&#x62;&#x6f;&#x62..snip..&#x65;&#x74;</a>

{'mail@example.com'|escape:'mail'}
smarty [AT] example [DOT] com

例 5-11. 別の例

PHP の関数を修飾子として使用できます。これは $security の設定によります。

{* "rewind" パラメータに現在の場所を登録します *}
<a href="{$SCRIPT_NAME}?page=foo&#38;rewind={$smarty.server.REQUEST_URI|urlencode}">click here</a>

これは email 用に便利です。しかし、 {mailto} も参照してください。

{* email アドレスを混乱させます *}
<a href="mailto:{$EmailAddress|escape:'hex'}">{$EmailAddress|escape:'mail'}</a>

Smarty の構文解析を回避{mailto} および E-mail アドレスを混乱させる のページも参照してください。

SEARCH