您的位置:首页 > 其它

Smarty模板变量操作符介绍

2012-08-02 22:39 351 查看
Smarty模板变量操作符介绍
capitalize [首字母大写],示例:{$smarty.get.name|capitalize}
count_characters [计算字符数],示例:{$smarty.get.name|count_characters}
cat [连接字符串],示例:{$smarty.get.name|cat:'welcome to www.phpernote.com'},连接两个变量如:{$smarty.get.name|cat:$smarty.get.password}
count_paragraphs [计算段落数],示例:{$smarty.get.name|count_characters}

count_sentences [计算句数],示例:{$smarty.get.name|count_sentences}
count_words [计算词数],示例:{$smarty.get.name|count_words}
date_format [时间格式],示例:{$smarty.server.request_time|date_format:"%Y-%m-%d %H:%M:%S"}或者{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"},显示格式如:2012-7-31 11:01:21
default [默认],示例:{$smarty.get.name|default:'phpernote.com'},意思是当没有接受到name参数或者接收到的name参数值为空的时候,使用phpernote.com代替这个值。

escape [转码],示例:{$smarty.get.name|escape:'url'} ?
indent [缩进],示例:{$smarty.get.name|indent:10:' '},段落首行缩进,这里示例是缩进了十个空格表示的字符。作用类似于css里面的text-indent。
lower [小写],示例:{$smarty.get.name|lower}
upper [大写],示例:{$smarty.get.name|upper}
nl2br [将变量中的\n(换行符)替换成<br />],示例:{$smarty.get.name|nl2br}
regex_replace [正则替换],示例:{$smarty.get.name|replace:"/[\r\t\n]/":"phpernote.com"},将变量中的符合正则的内容替换成指定内容
replace [替换],示例:{$smarty.get.name|replace:"baidu.com":"phpernote.com"},将变量中要求的内容替换成指定内容,示例的意思是将变量中所有baidu.com替换为phpernote.com。
spacify [插空],示例:{$smarty.get.name|spacify:"^^"},将变量字符与字符之间插入指定内容,包括空格。
string_format [字符串格式化],示例:{$smarty.get.namestring_format:"%d"},该操作是将变量中的内容格式化,格式化参数类同php的printf。
strip [去除(多余空格)],示例:{$smarty.get.name|strip:" "},如果存在第一个参数的话,则将空格替换为指定的内容,示例的意思是将空格都替换为" ";

strip_tags [去除html标签],示例:{$smarty.get.name|strip_tags}
truncate [截取],示例:{$smarty.get.name|truncate:10:'...'},示例的意思是截取10个字符,超出的部分用"..."代替,第二个参数为空的话,超出部分就直接省略了。
wordwrap [行宽约束],示例:{$smarty.get.name|wordwrap:30:"\n":true},将超过指定的长度的内容强制换行
今天就列举到此了,以后会慢慢补充和完善,更为具体的Smarty模板变量操作符知识大家可以参考Smarty手册!
原文地址:http://www.phpernote.com/php-template-framework/398.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: