Smarty 变量调节器
2012-11-12 19:06
330 查看
变量调节器主要应用于变量,还有自定义函数和字符串。使用”|”符号和调节器名称应用调节器。参数由”:”符号分开。
Example1. capitalize 首字大写
Variable_Modifiers.php
include ("../libs/Smarty.class.php");
$smarty = new Smarty();
$smarty->reInitSmarty("../demo/templates","../demo/templates_c","../demo/configs");
$string = "ni hao!";
$smarty->assign("cap",$string);
$smarty->display("variable_modifiers.tpl");
Variable_modifiers.tpl
Capitalize功能演示:<br>
原变量内容:<{$cap}><br>
应用后内容:<{$cap|capitalize}><br>
Example2. Count_characters 字符计数
Variable_Modifiers.php
include ("../libs/Smarty.class.php");
$smarty = new Smarty();
$smarty->reInitSmarty("../demo/templates","../demo/templates_c","../demo/configs");
$string = "ni hao!";
$smarty->assign("cap",$string);
$smarty->display("variable_modifiers.tpl");
Variable_modifiers.tpl
count_characters功能演示:<br>
<{$cap}>的字符个数为(不计空格):<{$cap|count_characters}><br>
<{$cap}>的字符个数为(计空格):<{$cap|count_characters:true}><br>
Example3. cat 字符串连接
Variable_Modifiers.php
include ("../libs/Smarty.class.php");
$smarty = new Smarty();
$smarty->reInitSmarty("../demo/templates","../demo/templates_c","../demo/configs");
$string = "ni hao!";
$smarty->assign("cap",$string);
$smarty->display("variable_modifiers.tpl");
Variable_modifiers.tpl
cat功能演示:<br>
给字符串<{$cap}>连接***之后:<{$cap|cat:"***"}><br>
Example4. count_paragraphs 计算段数
Variable_Modifiers.php
include ("../libs/Smarty.class.php");
$smarty = new Smarty();
$smarty->reInitSmarty("../demo/templates","../demo/templates_c","../demo/configs");
$string = "ni hao!\nnihaoma?";
$smarty->assign("cap",$string);
$smarty->display("variable_modifiers.tpl");
Variable_modifiers.tpl
count_paragraphs功能演示:<br>
<{$cap}>的段落个数为:<{$cap|count_paragraphs}>
Example5. count_sentences 计算句数
<{$cap}>的段落个数为:<{$cap|count_sentences}>
Example6. count_words 计算词数
<{$cap}>的段落个数为:<{$cap|count_words}>
Example7. date_format 日期格式*************
利用date_format格式化当前系统日期、时间:<br>
当前系统时间为:<{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}>
Example8. string_format 字符串格式化
<{*string_format格式参数:%d(十进制整数) %x(十六进制整数) %o(八进制整数) %u(无符号数显示)*}>
<{$num}>通过%md格式化:<{$num|string_format:"%10d"}><br>
<{$num}>通过%m.nf格式化一个实数:<{$num|string_format:"%.2f"}><br>
<{$num}>能过%e格式化一个实数:<{$num|string_format:"%.2e"}><br>
Example9. escape 编码
<{$cap|escape:"htmlall"|nl2br}>
相关文章推荐
- ecshop二次开发 自定义smarty模板的变量调节器
- smarty 中 变量调节器(1)
- smarty变量调节器和smarty缓存
- 夺命雷公狗---Smarty NO:06 设计篇4 变量调节器
- PHP Smarty变量调节器
- smarty变量调节器
- smarty模板详解四:块注册、变量调节器、变量调节器的注册
- smarty之变量调节器
- smarty变量调节器
- Smarty中常用的变量调节器
- Smarty的变量调节器
- smarty变量调节器与函数
- smarty变量调节器--date_format[格式化日期]
- Smarty变量调节器
- Smarty变量调节器2
- smarty自定义变量调节器的总结
- Smarty变量调节器
- smarty2 变量调节器Variable Modifiers
- Smarty之变量调节器
- Smarty变量调节器失效的解决办法