Variable Modifiers [变量调节器]

来源:互联网 发布:淘宝怎么举报刷销量 编辑:程序博客网 时间:2024/05/18 03:34

2012-11-12
Variable Modifiers [变量调节器
]
概念:变量调节器用于变量,自定义函数和字符串。
应用:
    1.使用‘|’符号和调节器名称应用调节器。变量调节器由赋予的参数值决定其行为。参数由‘:’

符号分开。
    2.给数组变量应用单值变量的调节,结果是数组的每个值都被调节。如果只想要调节器用一个值调节

整个数组,必须在调节器名字前加上@符号。例如: {$articleTitle|@count}(这将会在

$articleTitle 数组里输出元素的数目)

capitalize  首字母大写
count_characters[字符计数]
cat[连接字符串,将cat里的值连接到给定的变量后面.]
count_paragraphs[计算段数,计算变量里的段落数量。]
count_sentences[计算句数,计算变量里句子的数量。 ]
count_words[计算词数,计算变量里的词数]
date_format[格式化日期]

对变量调解器的练习:
Variable_Modifiers.php文件
  <?php
  include "init.inc.php";
  $string="hello yys!";
  $smarty->assign("cap",$string);
  $smarty->assign("num",123.345);
  $smarty->display("Variable_Modifiers.tpl");

  ?>

Variable_Modifiers.tpl文件
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="
http://www.w3.org/1999/xhtml">
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>测试变量调节器</title>
  </head>

  <body>
  Capitalize功能演示:<br/>
  原变量内容:<{$cap}><br>
  用后内容:<{$cap|capitalize}>
  <hr />
  count_characters功能演示:<br />
  <{$cap}>不计空格:<{$cap|count_characters}><br />
  <{$cap}>计空格:<{$cap|count_characters:true}><br />
  <hr />
  cat功能演示:<br />
  给字符串<{$cap}>加三个***:<{$cap|cat:"***"}><br />
  <hr />
  count_paragraphs功能演示:<br />
  <{$cap}>的段落个数为:<{$cap|count_paragraphs}><br />
  <hr />
  count_sentences功能演示:<br />
  <{$cap}>的句子个数为:<{$cap|count_sentences}><br />
  <hr />
  count_words功能演示:<br />
  <{$cap}>的词数为:<{$cap|count_words}><br />
  <hr />
  利用date_format格式化当前系统日期/时间:<br />
  当前系统时间为:<{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}>
  <hr/>
  <{*string_format格式参数:%md(十进制整数) %x(十六进制) %o(八进制整数) %u(无符号数显示) 

*}>
  <{$num}>通过%m.nf格式化一个实数:<{$num|string_format:"%.2f"}><br>
  <{$num}>通过%e格式化一个实数:<{$num|string_format:"%.2e"}>

  </body>
  </html>

原创粉丝点击