当前位置: 首页 > 图文教程 > 网络编程 > PHP > php smarty模版引擎中变量操作符及使用方法

PHP
PHP实例:用PHP简单实现多条件查询
PHP实例:用PHP实现多文件上载系统程序
PHP实例程序:用PHP制作登录页面程序
PHP实例:PHP取GB2312编码字符串首字母的方法
PHP实例:用PHP实现表单验证码登陆校验
Oracle与PHP实例开发Myers订单跟踪系统
PHP实例:email address 生成图片程序
PHP连接远程MYSQL和MYSQL5.1中文乱码处理方法
用 PHP 构建自定义搜索引擎
详细讲解PHP的Jmai组件及发送邮件实例
在动态网页技术PHP5中类(CLASS)的新特征
实例学习PHP如何实现在线发邮件
PHP上传文件的代码
不需要GD库的情况下实现验证码
PHP进阶教程:实现网站的无限分类
童虎:人人皆可做插件 Discuz! 插件开发实例讲解
创建论坛专业知识库 HDWiki(For Discuz!)V1.0正式版发布
PHP网站后门的隐藏技巧测试报告
加速PHP动态网站 MySQL索引分析和优化
php中rename()函数的妙用

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 39 ::
收藏到网摘: n/a

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>"}