8. Smarty 基本语法
来源:互联网 发布:久其软件 决算 编辑:程序博客网 时间:2024/06/04 23:48
2. Smarty 调节器(变量操作符)
3.自定义变量调节器(以插件形式)
TestController4.php
<?phprequire_once './libs/Smarty.class.php';$smarty = new Smarty();$smarty->left_delimiter = "{<";$smarty->right_delimiter = ">}";$smarty->assign("sal",'100');$smarty->assign("tax_rate",'0.08');//定义常量define('TAX_RATE','0.08');$smarty->assign("str1",'hello world');$smarty->assign("str2",'hello world\\n shanghai');$smarty->assign("str4",'hello world shanghai 上海');$smarty->assign("bb",'<a href="##">go to 搜狐</a>');$smarty->assign("article",file_get_contents('aa.txt'));$smarty->assign("cc",'1234abcdef9999ae ew e ew 2222wrwer3333');$smarty->assign("dd",'hello world aaa iii ');$smarty->assign("ee",'hello上海人 world aaa iii ');$smarty->assign("hh",'hello上海人 world aaa iii hello上海人 world aaa iii hello上海人 world aaa iii hello上海人 world aaa iii hello上海人 world aaa iii hello上海人 world aaa iii hello上海人 world aaa iii hello上海人 world aaa iii hello上海人 world aaa iii hello上海人 world aaa iii hello上海人 world aaa iii hello上海人 world aaa iii hello上海人 world aaa iii hello上海人 world aaa iii ');$smarty->display('test4.tpl');
test4.tpl
<h1> smarty 语法细节</h1><h2>个人所得税</h2>{<$sal*0.08+2-5>}<br/>{<$sal*$tax_rate>}<br/><h2>如何取出常量</h2>{<$smarty.const.TAX_RATE>}<br/>{<$smarty.const.TAX_RATE+100>}<h2>首字母大写</h2>{<$str1|capitalize:false>}<h2>自定义调节器</h2>{<"abcd"|mycap:'hello'>}<h2>统计字符</h2>{<$str1|count_characters>}<h2>统计段落数</h2>{<$str2|count_paragraphs>}<h2>统计单词数</h2>{<$str4|count_words>}<h2>显示当前时间</h2>{<$smarty.now|date_format:"%Y-%m-%d %H-%I-%S %a">}<h2>default使用</h2>{*如果这个变量有,就输出,没有就是 default的值*}{<$aa|default:"没有值">}<h2>escape</h2>{*默认形式*}{<$bb>}<br/>{*源码输出*}{<$bb|escape>}<h2>输出文件内容</h2>{*将文件的换行\r\n,替换成网页的< br/>*}{<$article|nl2br>}<h2>正则表达式的使用</h2>{<$cc|regex_replace:"/(\d\d\d\d)/":"这里有4个数">}<h2>spacify</h2>{<"abc"|spacify>}<br/>{<"abc"|spacify:"^_^">}<h2>去掉空格 strip</h2>{<$dd|strip:"||">}<h2>截取 truncate</h2>默认是 ... ,而且这3个点也要占位置<br/>{<$ee|truncate:9:"...":true>}<br/><a href="##" title='{<$ee>}'>{<$ee|truncate:9:"...":true>}</a><h2>行宽的约束</h2>{<$hh|wordwrap:50:"<br/>">}
<h2>测试 ismail</h2>{<"wj@sohu.com"|ismail>}
<?phpfunction smarty_modifier_ismail($str){ $pattern = '/^[a-zA-Z][a-zA-Z0-9_-]*@[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+$/i'; if(preg_match($pattern,$str)==1){ return '是一个合法的邮件'; }else{ return '不是一个合法的邮件'; }}
$smarty->assign("kk",'aaaaaaaaaabbbbbbbbbbbcccccccccccccccc');
<h2>组合使用</h2>{<$kk|upper|truncate:8>}
0 0
- 8. Smarty 基本语法
- smarty基本语法
- Smarty基本语法
- Smarty模板引擎基本语法的学习
- PHP 模板引擎Smarty的基本语法
- smarty模板引擎的基本语法
- smarty语法
- smarty语法
- php之Smarty基本语法和三大变量
- Smarty模板语法
- smarty的基本用法
- smarty的基本使用
- Smarty的基本配置
- smarty foreach 基本使用
- Smarty的基本配置【smarty.inc.php】
- Smarty核心内容:Smarty基本安装与调试
- Smarty学习之基础语法
- Smarty常用函数和语法
- A different object with the same identifier value was already associated with the session
- android 解决EditText无法失去焦点和失去焦点后隐藏软键盘的问题
- 含重复元素的全排列
- Unity学习笔记——利用脚本实现对一个物体的第三人称观察
- Unity基于NGUI实现拖拽功能
- 8. Smarty 基本语法
- Android 5.0之后 点击 悬浮穿回到顶部。
- Android中SQLite的使用
- [BZOJ3571][HNOI2014]画框
- POJ 2828 Buy Tickets(线段树—查找并更新从左到右的第i个1)
- fms服务端语法
- Android Hanlder综合
- XZ_iOS中推送通知~本地推送通知的实现
- 太阳理论