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 函数语法介绍一
Jun 14 PHP
Windows7下PHP开发环境安装配置图文方法
May 20 PHP
PHP设置一边执行一边输出结果的代码
Sep 30 PHP
php检测useragent版本示例
Mar 24 PHP
ThinkPHP3.1新特性之命名范围的使用
Jun 19 PHP
php简单实现查询数据库返回json数据
Apr 16 PHP
Smarty变量用法详解
May 11 PHP
thinkphp3.x连接mysql数据库的方法(具体操作步骤)
May 19 PHP
24条货真价实的PHP代码优化技巧
Jul 28 PHP
PHP之将POST数据转化为字符串的实现代码
Nov 03 PHP
php使用ftp实现文件上传与下载功能
Jul 21 PHP
PHP PDOStatement::setFetchMode讲解
Feb 03 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
深入PHP magic quotes的详解
2013/06/17 PHP
php number_format() 函数通过千位分组来格式化数字的实现代码
2013/08/06 PHP
PHP 数组基本操作小结(推荐)
2016/06/13 PHP
document.compatMode介绍
2009/05/21 Javascript
jQuery拖拽插件gridster使用指南
2015/04/21 Javascript
js中flexible.js实现淘宝弹性布局方案
2020/06/23 Javascript
BootStrap 图标icon符号图标glyphicons不正常显示的快速解决办法
2016/12/08 Javascript
bootstrap fileinput 插件使用项目总结(经验)
2017/02/22 Javascript
详解js的作用域、预解析机制
2018/02/05 Javascript
vue中使用codemirror的实例详解
2018/11/01 Javascript
使用 vue 实现灭霸打响指英雄消失的效果附demo
2019/05/06 Javascript
python统计cpu利用率的方法
2015/06/02 Python
学习Python3 Dlib19.7进行人脸面部识别
2018/01/24 Python
Python运维自动化之nginx配置文件对比操作示例
2018/08/29 Python
对python多线程中互斥锁Threading.Lock的简单应用详解
2019/01/11 Python
对python3 sort sorted 函数的应用详解
2019/06/27 Python
手写一个python迭代器过程详解
2019/08/27 Python
Python数组并集交集补集代码实例
2020/02/18 Python
总结Pyinstaller的坑及终极解决方法(小结)
2020/09/21 Python
python利用xlsxwriter模块 操作 Excel
2020/10/14 Python
Desigual德国官网:在线购买原创服装
2018/03/27 全球购物
英国太阳镜品牌:Taylor Morris Eyewear
2018/04/18 全球购物
SEPHORA丝芙兰捷克官网:购买香水、化妆品和护肤品
2018/11/26 全球购物
含精油的天然有机化妆品:Indemne
2019/08/27 全球购物
Booking.com德国:预订最好的酒店和住宿
2020/02/16 全球购物
如何估计一张表的大小(假设该表中有1万条数据)
2016/03/27 面试题
老师给学生的表扬信
2014/01/17 职场文书
毕业生自荐书
2014/02/02 职场文书
医院总经理岗位职责
2014/02/04 职场文书
团日活动总结怎么写
2014/06/25 职场文书
2014年政协委员工作总结
2014/12/01 职场文书
大队委员竞选稿
2015/11/20 职场文书
员工工作失职检讨书范文!
2019/07/03 职场文书
python函数指定默认值的实例讲解
2021/03/29 Python
Python Parser的用法
2021/05/12 Python
Oracle中日期的使用方法实例
2022/07/07 Oracle