escape

パラメータの位置?必須有効な値デフォルト概要
1string?Nohtml,htmlall,url,quotes,hex,hexentity,javascripthtml使用するエスケープフォーマット

htmlエスケープ・urlエスケープ・未エスケープの変数のシングルクォートのエスケープ・hexエスケープ・hexentityエスケープ・javascriptエスケープを行います。デフォルトではhtmlエスケープが行われます。


例 5-10. escape

<?php

$smarty = new Smarty;
$smarty->assign('articleTitle', "'Stiff Opposition Expected to Casketless Funeral Plan'");
$smarty->display('index.tpl');

?>

index.tpl :

{$articleTitle}
{$articleTitle|escape}
{$articleTitle|escape:"html"} {* & " ' < > をエスケープ *}
{$articleTitle|escape:"htmlall"} {* 全てのhtmlエンティティをエスケープ *}
{$articleTitle|escape:"url"}
{$articleTitle|escape:"quotes"}
<a href="mailto:{$EmailAddress|escape:"hex"}">{$EmailAddress|escape:"hexentity"}</a>
出力 :

'Stiff Opposition Expected to Casketless Funeral Plan'
'Stiff Opposition Expected to Casketless Funeral Plan'
'Stiff Opposition Expected to Casketless Funeral Plan'
'Stiff Opposition Expected to Casketless Funeral Plan'
%27Stiff+Opposition+Expected+to+Casketless+Funeral+Plan%27
\'Stiff Opposition Expected to Casketless Funeral Plan\'
<a href="mailto:%62%6f%62%40%6d%65%2e%6e%65%74">bob@me.net</a>

2005年07月08日(金) 10:57:24 Modified by smarten




スマートフォン版で見る