变量调节器

上一篇 / 下一篇  2007-04-19 16:27:36 / 个人分类:smart学习

{* Truncate the topic to 40 characters use ... at the end *}
{* 取其前40个字符 *}
Topic: {$topic|truncate:40:"..."}

{$articleTitle}计算变量里的字符数
{$articleTitle|count_characters}

字符串连接
$smarty->assign('articleTitle', 'Psychics predict world didn't end');
{$articleTitle|cat:" yesterday."}
Psychics predict world didn't end yesterday.

计算变量里句子的数量
{$articleTitle|count_sentences}

计算变量里的词数
{$articleTitle}
{$articleTitle|count_words}

lower 小写
{$articleTitle}
{$articleTitle|lower}
OUTPUT:
Two Convicts Evade Noose, Jury Hung.
two convicts evade noose, jury hung.

upper 大写  将变量改为大写

capitalize 首字大写
{$articleTitle}
{$articleTitle|capitalize}
OUTPUT:
Police begin campaign to rundown jaywalkers.
Police Begin Campaign To Rundown Jaywalkers
 
nl2br
换行符替换成<br />
{$articleTitle|nl2br}
$smarty->assign('articleTitle', "Sun or rain expected\ntoday, dark tonight");
Sun or rain expected<br />today, dark tonight

replace 替换
$smarty->assign('articleTitle', "Child's Stool Great for Use in Garden.");
{$articleTitle|replace:"Garden":"Vineyard"}
Child's Stool Great for Use in Vineyard.

spacify 插空 是一种在字符串的每个字符之间插入空格或者其他的字符(串).
$smarty->assign('articleTitle', 'Something Went Wrong in Jet Crash, Experts Say.');
{$articleTitle|spacify:"^^"}
s^^o^^m^^e^^t^^h^^i^^n^^g^^ ^^W^^e^^n^^t^^ ^^W^^r^^o^^n^^g^^ ^^i^^n^^ ^^J^^e^^t^^ ^^C^^r^^a^^s^^h^^,^^ ^^E^^x^^p^^e^^r^^t^^s^^ ^^S^^a^^y^^.

string_format 字符串格式化 是一种格式化浮点数的方法.例如十进制数.使用sprintf语法格式化
$smarty->assign('number', 23.5787446);
{$number|string_format:"%.2f"}
{$number|string_format:"%d"}
23.58
24

strip去除(多余空格) 替换所有重复的空格,换行和tab为单个
$smarty->assign('articleTitle', "Grandmother of\neight makes\t    hole in one.");
{$articleTitle|strip}
{$articleTitle|strip:"&nbsp;"}
Grandmother of eight makes hole in one.
Grandmother&nbsp;of&nbsp;eight&nbsp;makes&nbsp;hole&nbsp;in&nbsp;one

strip_tags 去除html标签  去除在<和>之间的所有标签,包括<和>.
$smarty->assign('articleTitle', "Blind Woman Gets <font face=\"helvetica\">New Kidney</font> from Dad she Hasn't Seen in <b>years</b>.");
{$articleTitle|strip_tags}
Blind Woman Gets New Kidney from Dad she Hasn't Seen in years.

 

eq equal ==
ne not equal !=
cmp compare <=>
lt less than <
gt greater than>

 

 

 

 

 


 


TAG: smart 笔记 smart学习

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar