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

2015-01-24信息快讯网

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

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下通过exec获得计算机的唯一标识[CPU,网卡 MAC地址]
常用的PHP数据库操作方法(MYSQL版)
php 数组使用详解 推荐
php smarty 二级分类代码和模版循环例子
php学习之变量的使用
mac下使用brew配置环境的步骤分享
PHP操作mysql函数详解,mysql和php交互函数
php中全局变量global的使用演示代码
php的list()的一步操作给一组变量进行赋值的使用
用PHP的超级变量$_POST获取HTML表单(HTML Form) 数据
PHP操作MongoDB时的整数问题及对策说明
在smarty模板中使用PHP函数的方法
fleaphp crud操作之find函数的使用方法
PHP session有效期session.gc_maxlifetime
Php Mssql操作简单封装支持存储过程
phpmyadmin导入(import)文件限制的解决办法
php smarty模版引擎中的缓存应用
php smarty模版引擎中的缓存应用
PHP MYSQL乱码问题,使用SET NAMES utf8校正
php操作sqlserver关于时间日期读取的小小见解
PHP Session变量不能传送到下一页的解决方法
php 静态变量的初始化
php header 详细使用说明与使用心得第1/2页
PHP 向右侧拉菜单实现代码,测试使用中
phpmailer 中文使用说明(简易版)
PHP 程序员应该使用的10个组件
PHP 判断变量类型实现代码
PHP 变量类型的强制转换
PHP教程 预定义变量
PHP获取163、gmail、126等邮箱联系人地址【已测试2009.10.10】
PHP5 操作MySQL数据库基础代码
封装一个PDO数据库操作类代码
MayFish PHP的MVC架构的开发框架
discuz7 phpMysql操作类
php xml文件操作实现代码(二)
©2014-2024 dbsqp.com