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
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
相关文章推荐
- Smarty模板变量操作符介绍 (转化为小数点型)
- PHP模板引擎Smarty之配置文件在模板变量中的使用方法示例
- [转]帝国cms目录结构与模板结构以及标签变量介绍
- 陈力:传智播客古代 珍宝币 泡泡龙游戏开发第51讲:PHP中smarty模板技术介绍
- 编写Smarty插件在模板中直接加载数据的详细介绍
- php smarty模版引擎中变量操作符及使用方法
- 我的php学习笔记(二十五)PHP模板引擎Smarty的变量操作符
- smarty模板内容捕捉与变量修饰器
- Smarty----变量操作符
- 模板引擎Smarty介绍
- 编写Smarty插件在模板中直接加载数据的详细介绍
- PHP模板引擎Smarty的变量操作符
- smarty模板操作变量
- smarty_smarty实用的变量操作符
- SMARTY模板中如何使用get,post,request,cookies,session,server变量
- Smarty模板变量调节器用法分析
- smarty模板 变量 运算符 表达式 流程控制 函数
- Smarty中常用变量操作符汇总
- smarty模板引擎_3-预保留变量
- 问题:smarty模板变量修饰函数regex_replace 替换中文问题?