smarty重点.docx
- 文档编号:9969129
- 上传时间:2023-02-07
- 格式:DOCX
- 页数:81
- 大小:45.43KB
smarty重点.docx
《smarty重点.docx》由会员分享,可在线阅读,更多相关《smarty重点.docx(81页珍藏版)》请在冰豆网上搜索。
smarty重点
Example5-2.capitalize
例5-2.首字大写
index.php:
$smarty=newSmarty;
$smarty->assign('articleTitle','Policebegincampaigntorundownjaywalkers.');
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|capitalize}
OUTPUT:
Policebegincampaigntorundownjaywalkers.
PoliceBeginCampaignToRundownJaywalkers.
Example5-3.count_characters
index.php:
$smarty=newSmarty;
$smarty->assign('articleTitle','ColdWaveLinkedtoTemperatures.');
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|count_characters}
{$articleTitle|count_characters:
true}//决定是否计算空格
OUTPUT输出:
ColdWaveLinkedtoTemperatures.
29
33
Example5-4.cat将cat里的值连接到给定的变量后面.
index.php:
$smarty=newSmarty;
$smarty->assign('articleTitle',"Psychicspredictworlddidn'tend");
$smarty->display('index.tpl');
index.tpl:
{$articleTitle|cat:
"yesterday."}
OUTPUT:
Psychicspredictworlddidn'tendyesterday.
Example5-5.count_paragraphs计算变量里的段落数量。
index.php:
$smarty=newSmarty;
$smarty->assign('articleTitle',"WarDimsHopeforPeace.Child'sDeathRuinCouple'sHoliday.\n\nManisFatallySlain.DeathCausesLoneliness,FeelingofIsolation.");
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|count_paragraphs}
OUTPUT:
WarDimsHopeforPeace.Child'sDeathRuinsCouple'sHoliday.
ManisFatallySlain.DeathCausesLoneliness,FeelingofIsolation.
2
Example5-6.count_sentences计算变量里句子的数量
index.php:
$smarty=newSmarty;
$smarty->assign('articleTitle','TwoSovietShipsCollide-OneDies.EnragedCowInjuresFarmerwithAxe.');
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|count_sentences}
OUTPUT:
TwoSovietShipsCollide-OneDies.EnragedCowInjuresFarmerwithAxe.
2
Example5-7.count_words计算变量里的词数
index.php:
$smarty=newSmarty;
$smarty->assign('articleTitle','DealersWillHearCarTalkatNoon.');
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|count_words}
OUTPUT:
DealersWillHearCarTalkatNoon.
7
Example5-10.default为空变量设置一个默认值。
当变量为空或者未分配的时候,将由给定的默认值替代输出。
index.php:
$smarty=newSmarty;
$smarty->assign('articleTitle','DealersWillHearCarTalkatNoon.');
$smarty->display('index.tpl');
index.tpl:
{$articleTitle|default:
"notitle"}
{$myTitle|default:
"notitle"}
OUTPUT:
DealersWillHearCarTalkatNoon.
notitle
Example5-11.escape用于html转码,url转码,在没有转码的变量上转换单引号,十六进制转码,十六进制美化,或者javascript转码。
默认是html转码。
index.php:
$smarty=newSmarty;
$smarty->assign('articleTitle',"'StiffOppositionExpectedtoCasketlessFuneralPlan'");
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|escape}
{$articleTitle|escape:
"html"}{*escapes&"'<>*}
{$articleTitle|escape:
"htmlall"}{*escapesALLhtmlentities*}
{$articleTitle|escape:
"url"}
{$articleTitle|escape:
"quotes"}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- smarty 重点
![提示](https://static.bdocx.com/images/bang_tan.gif)