Get Smarty

Donate

Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Advertisement

escape

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

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

Example 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'}">click here</a>
<a
href="?title=%27Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan%27">click here</a>

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

<a href="mailto:{$EmailAddress|escape:"hex"}">{$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

   

Example 5.11. 別の例

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


{* "rewind" パラメータに現在の場所を登録します *}
<a href="{$SCRIPT_NAME}?page=foo&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 アドレスを混乱させる のページも参照してください。

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors