1,
variable_modifiers.php
<?php
include ("../libs/Smarty.class.php");
$smarty = new Smarty();
$smarty->caching=2;
$smarty->template_dir="../demo/templates";
$smarty->compile_dir="../demo/templates_c";
$smarty->config_dir="../demo/configs";
$smarty->cache_dir="../demo/caches";
$smarty->left_delimiter="<{";
$smarty->right_delimiter="}>";
$smarty->cache_lifetime=10;
$string = "hello word! \n PHP";
$smarty->assign("cap",$string);
$smarty->assign("num",123.4567890123);
$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|escape:"hex"}><br />
应用首字母大写后内容:<{$cap|capitalize}><br />
<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}>通过%md格式化:<{$num|string_format:"%10d"}><br>
<$num>通过%d.nf格式化一个实数:<{$num|string_format:"%.2f"}><br>
<$num>通过%d.nfe格式化一个实数:<{$num|string_format:"%4.1e"}><br>
<hr>
lower小写功能演示:<br>
<{$cap|lower}><br>
<hr>
upper大写功能演示:<br>
<{$cap|upper}><br>
<hr>
replace替换功能演示:<br>
<{$cap|replace:"hello":"hi"}><br>
<hr>
<{$cap}>应用缩进之后:<br>
<{$cap|indent:4:" "}><br>
<hr>
<{$cap}>应用truncate截取字符串后的效果:<br>
<{$cap|truncate:5:"***":true}><br>
<hr>
<$cap>应用spacify插空之后的效果:<br>
<{$cap|upper|spacify:"*"}><br>
<hr>
<{$cap}>应用default为空变量设置一个默认值:<br>
<{$cap|default:"no title"}><br>
<{$nocap|default:"no title"}><br>
<hr>
<{$cap}>应用nl2br之后效果:<br>
<{$cap|nl2br}><br>
<hr>
<{$cap}>应用changecolor之后的效果:<br>
<{$cap|changecolor}><br>
<{$cap|changecolor:"green":"40"}><br>
</body>
</html>
2,
modifiers.changecolor.php
<?php
function smarty_modifier_changecolor($string,$color='red',$size='40'){
$string="<font color='".$color."' size='".$size."'>".$string."<font>";
return $string;
}
?>