Smarty变量调节器的使用
生活随笔
收集整理的這篇文章主要介紹了
Smarty变量调节器的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
[php]?view plaincopy print? $str?=?'how?Are?you';?? $smarty->assign('str',?$str);?? ?? $title?=?"\nbbbbbb。bbbb\n1111111\nbbbbbbbb\n222.\t22.22";?? $smarty->assign('title',$title);?? ?? $name?=?"who?are?\n?you?";?? $smarty->assign('name',$name);?? ?? $address?=?"<center>I'm?center</center><sm>ddddddd</sm>";?? $smarty->assign('address',$address);?? ?? $leg?=?"1a2?admin?b3c4d5e6g7h8i9j";?? $smarty->assign('leg',$leg);?? ?? $file?=?"hi?who?are?you?where?are?from";?? $smarty->assign('file',$file);?? ?? $num?=?123.4567;?? $smarty->assign('num',$num);?? ?? $content?=?"hit?me?<a?href='#'>this?is?a?test</a><?c=admin&a=input>aaa@admin.com";?? $smarty->assign('content',$content);?? ?? $smarty->display('index.html');??????//顯示index.html??
<{$str}><br>?? <{$str|capitalize}><{*首字母大寫*}><br>?? <{$str|upper}><{*全部大寫*}><br>?? <{$str|lower}><{*全部小寫*}><br>?? <{$str|lower|upper}><{*全部大寫,調節從左至右*}><br>?? <{$str|count_characters}><{*統計字符的個數*}><br>?? <{$str|count_characters:true}><{*統計字符的個數,包括空格*}><br>?? <{$str|cat:"??????"}><{*連接到變量的值后面*}><br><br>?? ?? <{$title|count_paragraphs}><{*統計變量中段落的個數,即相鄰\n或\r的會算為一個*}><br>?? <{$title|count_sentences}><{*統計變量中句子的個數*}><br>?? <{$title|count_words}><{*統計變量中單詞的個數*}><br><br>?? ?? <{$smarty.now|date_format:"%Y-%m-%d?%p?%H:%M:%S?week:%W"}><{*當前時間2012-04-25?AM?08:20:17?week:17*}><br><>br?? ?? <{$user|default:"null"}><{*如果變量為空或者不存在時,輸出默認的值,即default的值*}><br><br>?? ?? <{$name}><br>?? <{$name|indent}><br>?? <{$name|indent:10}><br>?? <{$name|indent:1:"\t"}><br><br>?? ?? <{$name|regex_replace:"/[\r\n\t]/":"string"}><{*正則替換*}><br><br>?? ?? <{$name|replace:"who":"where"}><{*替換*}><br><br>?? ?? <{$name|spacify:"!"}><{*在字符之間插入字符*}><br><br>?? ?? <{$name|strip}><{*用空格或指定字符替換所有重復空格、換行、制表符*}><br>?? <{$name|strip:"?"}><br><br>?? ?? <{$address}><br>?? <{$address|strip_tags}><{*去掉<>標簽及中間的內容*}><br><br>?? ?? <{$leg|truncate}><{*字符串截取,默認80個字符*}><br>?? <{$leg|truncate:10}><{*字符串截取,前10個,包括...三個字符*}><br>?? <{$leg|truncate:10:""}><{*字符串截取,前10個字符,不用...代替后面的內容*}><br>?? <{$leg|truncate:10:"---"}><{*字符串截取,前10個字符,以單詞結束,用---代替后面的內容*}><br>?? <{$leg|truncate:10:"...":true}><{*字符串截取,前10個字符,精確個數,用...代替后面的內容*}><br>?? <{$leg|truncate:10:"":true}><{*字符串截取,前10個字符,不用...代替后面的內容*}><br><br>?? ?? <{$file}><br>?? <{$file|wordwrap:10}><{*10字符為一行*}><br>?? <{$file|wordwrap:10:"<br>\n"}><{*10字符為一行*}><br>?? <{$file|wordwrap:10:"\n":true}><{*10字符為一行*}><br><br>?? ?? ?? <{$num}><br>?? <{$num|string_format:"%.2f"}><{*取兩位小數,四舍五入*}><br>?? <{$num|string_format:"%d"}><{*取整*}><br><br>?? ?? ?? <{$content}><br>?? <{$content|escape}><br>?? <{$content|escape:"html"}><br>?? <{$content|escape:"htmlall"}><br>?? <{$content|escape:"url"}><br>?? <{$content|escape:"quotes"}><br>?? <{$content|escape:"hex"}><br>?? <{$content|escape:"hexentity"}><br>?? <{$content|escape:"javascript"}><br>??
html
[html]?view plaincopy print?
變量調節器,可以組合使用,來達到顯示的效果,用"|"分隔,從左到右執行
結果:
總結
以上是生活随笔為你收集整理的Smarty变量调节器的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Smarty中的变量
- 下一篇: Smarty中的内建函数(一)confi