Get Smarty

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:

Check reviews of PHP Web Hosting, compatible with Smarty Templates

escape

Используется для кодирования / экранирования спецсимволов по алгоритмам экранирования HTML, URL'ов, одиночных кавычек, hex-экранирования, hex-сущностей, javascript и экранирования почтовых адресов. По умолчанию активирован режим экранирования HTML.

Позиция параметра Тип Обязателен Possible Values По умолчанию Описание
1 string Нет html,htmlall,url,urlpathinfo,quotes,hex,hexentity,javascript,mail html формат экранирования
2 string Нет 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');
?>

   

Шаблон:


{$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>
{$EmailAddress|escape:'mail'}    {* конвертирует e-mail в текст *}
{'mail@example.com'|escape:'mail'}

   

Результат обработки:


'Stiff Opposition Expected to Casketless Funeral Plan'
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;
%27Stiff+Opposition+Expected+to+Casketless+Funeral+Plan%27
\'Stiff Opposition Expected to Casketless Funeral Plan\'
<a href="mailto:%62%6f%..snip..%65%74">&#x62;&#x6f;&#x62..snip..&#x65;&#x74;</a>
smarty [AT] example [DOT] com
mail [AT] example [DOT] com

   

Обратите внимание, что родные функции PHP могут использоваться в качестве модификаторов, так что следующие приёмы сработают


{* GET-переменная rewind передает текущий адрес *}
<a href="{$SCRIPT_NAME}?page=foo&rewind={$smarty.server.REQUEST_URI|urlencode}">click here</a>
 
   

Это очень полезно для e-mail'ов, но см. также {mailto}


{* email address mangled *}
<a href="mailto:{$EmailAddress|escape:'hex'}">{$EmailAddress|escape:'mail'}</a>

   

См. также Предотвращение обработки Smarty, {mailto} и Сокрытие E-mail адреса.

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 10 plus 10? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
Cheap Hosting @HostsVault
email marketing @ActiveCampaign
broadband deals @BroadbandGenie
Best UK Web Hosting @webhost.uk.net
Reliable UK and US Web Hosting @rshosting.com
Cheap US and UK Web Hosting @infrenion.com
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Speed Test @broadbandspeed.co.uk
bulk email software @americaint.com