php smarty模版引擎中变量操作符及使用方法


Posted in PHP onDecember 11, 2009

smarty常用的20个变量操作符 * 使用语法:{变量名|操作符:}
* capitalize ---首字母大写
* count_characters ---计算字符数
* cat ---连接字符串
* count_paragraphs ---计算段落数
* count_sentences ---计算句数
* count_words ---计算词数
* date_format ---时间格式
* default ---默认
* escape ---转码
* indent ---缩进
* lower ---小写
* nl2br ---换行符替换为
* regex_replace ---正则替换
* replace ---替换
* spacify ---插空
* string_format ---字符串格式化
* strip ---去除多余空格
* strip_tags ---去除html标签
* truncate ---截取
* upper ---大写
* wordwrap --约束行宽

使用方法:
index.php

include("smarty_inc.php"); $name = "My name is MaJi,age 22,sex boy.<a href=>aaaaaa</a>."; 
$smarty->assign("title", $name); 
$smarty->assign("row", $row); 
$smarty->assign("d",strtotime("-0")); 
$smarty->assign("nubmer", 342345.736524); 
$smarty->display("index.html"); 
?>

index.html
原始数据:{$title}

使用capitalize变量操作符后:{$title|capitalize}
使用count_characters变量操作符后:{$title|count_characters}
使用cat变量操作符后:{$title|cat:"wwww.baidu.com"}
使用count_paragraphs变量操作符后:{$title|count_paragraphs}
使用count_sentences变量函数操作符后:{$title|count_sentences}
使用count_words变量函数操作后:{$title|count_words}
原始时间数据:{$d}
使用date_format变量函数操作:{$d|date_format:"%Y-%m-%d"}
使用smarty.now调用时间:{$smarty.now|date_format:"%Y-%m-%d"}
使用default变量函数操作:{$title1|default:"没有这个变量"}
使用escape变量函数操作:{$title|escape:"html"}
使用indent变量函数操作:{$title|indent:2:" "}
使用lower变量函数操作: {$title|lower}
使用upper变量函数操作:{$title|upper}
使用replace变量函数操作:{$title|replace:"is":"@@"}
使用spacify变量函数操作:{$title|spacify:"_"}
使用string_format变量函数操作:{$nubmer|string_format:"%.2f"}
使用strip变量函数操作:{$title|strip:"_"}
使用strip_tags变量函数操作:{$title|strip_tags}
使用truncate变量函数操作:{$title|truncate:30:"..."}
使用wordwrap变量函数操作:{$title|wordwrap:10:"<br>"}

PHP 相关文章推荐
浅谈PHP语法(1)
Oct 09 PHP
php一个找二层目录的小东东
Aug 02 PHP
php中计算未知长度的字符串哪个字符出现的次数最多的代码
Aug 14 PHP
使用Smarty 获取当前日期时间和格式化日期时间的方法详解
Jun 18 PHP
支持生僻字且自动识别utf-8编码的php汉字转拼音类
Jun 27 PHP
PHP 正则表达式常用函数
Aug 17 PHP
Symfony2框架学习笔记之HTTP Cache用法详解
Mar 18 PHP
PHP实现冒泡排序的简单实例
May 26 PHP
PHP实现支付宝即时到账功能
Dec 21 PHP
PHP实现求两个字符串最长公共子串的方法示例
Nov 17 PHP
thinkphp整合系列之极验滑动验证码geetest功能
Jun 18 PHP
php使用event扩展的io复用测试的示例
Oct 20 PHP
phpmyadmin导入(import)文件限制的解决办法
Dec 11 #PHP
php smarty模版引擎中的缓存应用
Dec 11 #PHP
php5 图片验证码实现代码
Dec 11 #PHP
php下图片文字混合水印与缩略图实现代码
Dec 11 #PHP
一个比较简单的PHP 分页分组类
Dec 10 #PHP
PHP 采集程序中常用的函数
Dec 09 #PHP
Php 构造函数construct的前下划线是双的_
Dec 08 #PHP
You might like
snoopy PHP版的网络客户端提供本地下载
2008/04/15 PHP
基于PHP Socket配置以及实例的详细介绍
2013/06/13 PHP
CURL状态码列表(详细)
2013/06/27 PHP
在Win7 中为php扩展配置Xcache
2014/10/08 PHP
PHP程序员学习使用Swoole的理由
2018/06/24 PHP
Javscript删除数组中指定元素并返回新数组
2014/03/06 Javascript
Bootstrap中的表单验证插件bootstrapValidator使用方法整理(推荐)
2016/06/21 Javascript
jQuery动态生成不规则表格(前后端)
2017/02/21 Javascript
自带气泡提示的vue校验插件(vue-verify-pop)
2017/04/07 Javascript
Vue实现动态显示textarea剩余字数
2017/05/22 Javascript
详解使用Typescript开发node.js项目(简单的环境配置)
2017/10/09 Javascript
VUE饿了么树形控件添加增删改功能的示例代码
2017/10/17 Javascript
node.js使用express框架进行文件上传详解
2019/03/03 Javascript
Vue 使用计时器实现跑马灯效果的实例代码
2019/07/11 Javascript
JavaScript相等运算符的九条规则示例详解
2019/10/20 Javascript
[00:05]ChinaJoy现场 DOTA2玩家高呼“CN DOTA BEST DOTA”
2019/08/04 DOTA
Python 命令行参数sys.argv
2008/09/06 Python
用python实现的可以拷贝或剪切一个文件列表中的所有文件
2009/04/30 Python
python实现下载整个ftp目录的方法
2017/01/17 Python
Python面向对象之类和对象属性的增删改查操作示例
2018/12/14 Python
由面试题加深对Django的认识理解
2019/07/19 Python
Python shelve模块实现解析
2019/08/28 Python
python中property属性的介绍及其应用详解
2019/08/29 Python
Pytorch Tensor基本数学运算详解
2019/12/30 Python
Python MySQLdb 执行sql语句时的参数传递方式
2020/03/04 Python
Keras-多输入多输出实例(多任务)
2020/06/22 Python
Python3+selenium配置常见报错解决方案
2020/08/28 Python
Python实现迪杰斯特拉算法过程解析
2020/09/18 Python
css3中flex布局宽度不生效的解决
2020/12/09 HTML / CSS
英国知名的皮手套品牌:Dents
2016/11/13 全球购物
雅诗兰黛(Estee Lauder)英国官方网站:世界顶级化妆品牌
2016/12/29 全球购物
医生自荐信
2013/10/11 职场文书
法律专业应届本科毕业生求职信
2013/10/25 职场文书
大学军训感想
2014/02/12 职场文书
理工大学毕业生自荐信范文
2014/02/22 职场文书
门面租赁合同范文
2019/08/06 职场文书