Smarty变量调节器

变量调节器 即Smarty函数:
1、capitalize:将变量离得所有单词首字母大写
index.php:
$smarty = new Smarty;
$smarty->assign('cap', '$article');
$smarty->display('index.tpl');

index.tpl
Capitalize功能演示:<br />
原变量内容:<{$cap}><br />
应用后的内容<{$cap|capitalize}><br />

2、count_characters计算变量里的字符个数(计算空格/不计算空格)
index.php:
$smarty = new Smarty;
$smarty->assign('cap', '$article');
$smarty->display('index.tpl');

index.tpl
<{$cap}>的字符个数是(不计空格):<{$cap|count_characters}><br />
<{$cap}>的字符个数是(计算空格):<{$cap|count_characters:true}>

3、cat连接字符串,将cat里的值连接到变量后
index.php:
$smarty = new Smarty;
$smarty->assign('cap', '$article');
$smarty->display('index.tpl');

index.tpl
给字符串<{$cap}>连接***之后:<{$cap|cat:"***"}>

4、count_paragraphs计算变量里的段落数
index.php:
$smarty = new Smarty;
$smarty->assign('cap', '$article');
$smarty->display('index.tpl');

index.tpl
<{$cap}>的段落个数是:<{$cap|count_paragraphs}>

5、count_sentences计算变量里的句子的数量
index.php:
$smarty = new Smarty;
$smarty->assign('cap', '$article');
$smarty->display('index.tpl');

index.tpl
<{$cap}>的句子个数是:<{$cap|count_sentences}>

6、count_words计算变量里的词数
index.php:
$smarty = new Smarty;
$smarty->assign('cap', '$article');
$smarty->display('index.tpl');

index.tpl
<{$cap}>的单词个数是:<{$cap|count_words}>

7、date_format格式化日期
index.tpl
当前系统时间是:<{$smarty.now|date_format:" %Y-%m-%d %H:%M:%S "}><br>

8、escape编码 用于html转码,url转码,在没有转码的变量上转换单引号,十六进制转码,十六进制美化,或者javascript转码。默认是html转码。
9、string_format字符串格式化
index.tpl
<{$num}>通过%md格式化:<{$num|string_format:"%d"}><br />
<{$num}>通过%md格式化:<{$num|string_format:"%10d"}><br />
<{$num}>通过%m.nf格式化一个实数:<{$num|string_format:"%.2f"}><br />
<{$num}>通过%m.nf格式化一个实数:<{$num|string_format:"%10.2f"}><br />
<{$num}>通过%e格式化:<{$num|string_forsmat:"%2.1e"}><br />

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值