变量调节器主要应用于变量,还有自定义函数和字符串。使用”|”符号和调节器名称应用调节器。参数由”:”符号分开。
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}>