夺命雷公狗---Smarty NO:05 设计篇3 变量调节器
{$var|date_format:”%Y%m%d”} :时间格式化,%Y-%m-%d %H:%M:%S
{$var|default:”value”} :当变量为空时,设置默认值
{$var|escape} :html转码
{$var|indent:10:”*”} :字符缩进
{$var|lower} :转小写
{$var|upper} :转大写
{$var|nl2br} :把\n转化为br标签
demo3.html
<!DOCTYPE html> <html> <head> <meta charset=’utf-8′> <title></title> </head> <body> 当前系统事件:{$smarty.now|date_format:”%Y-%m-%d %H:%M:%S”} <hr/> 默认值:{$val|default:’未查询到该变量’} <hr/> escape转码:{$str3|escape} <hr/> Indent字符缩进:{$str|indent:10:’*’}<!–这里的*好是代替字符–> <hr/> 转大写:{$str|upper} <hr/> nl2br:{$str|nl2br}<!–将变量值中的”\n”回车全部转换成HTML的 <br />–> <hr/> </body> </html>
demo3.php
<?php require “smarty/Smarty.class.php”; $smarty = new Smarty(); $str = “hello world”; $str2 = “nihao php”; $str3 = “<ul><li>hello ul li</li></ul>”; $smarty -> assign(‘str’,$str); $smarty -> assign(‘str2′,$str2); $smarty -> assign(‘str3′,$str3); $smarty -> display(“demo3.html”);