<!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> <script src="/jquery-1.11.2.min.js"></script> <script type="text/javascript"> $(document).ready(function(e) { $(".xs").mouseover(function(){ $(this).children("div").css("display","block"); }) $(".xs").mouseout(function(){ $(this).children("div").css("display","none"); }) }); </script> </head> <body> <{$test|capitalize}> <!--在显示的时候首字母大写--> <div><{$money|cat:"$"}></div><!--连接字符串--> <div><{"$"|cat:$money}></div> <div><{$zifu|count_characters}></div><!--计算字符数量--> <div><{$riqi|date_format:"%Y-%m-%d %H:%M:%S"}></div> <div><{$riqi|date_format:"%D %T"}></div><!--格式化日期--> <div><{$moren|default:"hello"}></div><!--模板默认值,没有注册值就是该显示的--> <div><{$suojin|indent:2}></div><!--字符缩进,默认是缩进4个--> <div><{$zhengze|regex_replace:"/d/":"oo"}></div><!--正则替换,第一个是要替换的内容,第二个是用什么来替换--> <div><{$zhengze|replace:"l":"0"}></div><!--一般的替换--> <div><{$jiequ|truncate:8:"***"}></div><!--字符串截取,截取几个字符,后面用什么代替--> <div><{$ceshi|yangshi:"yellow":24px}></div> <div><{$jiequ|substr:6:"***"}></div> <div><{$sex|sexname}></div> <div><{$nation|nationname}></div> <div class='xs' style='300px; height:30px; background-color:pink'> <span><{$xianshi|substr:30:"***"}></span> <div style='200px; height:100px; background-color:pink; display:none'><{$xianshi}></div> </div> </div> <{foreach $shuzu as $v}> <div class='xs' style='300px; height:30px; background-color:pink'> <span><{$v|substr:30:"***"}></span> <div style='200px; height:100px; margin:0xp 0px 0px 500px; background-color:pink; display:none'><{$v}></div> </div> <{/foreach}> </body> </html>
<?php function smarty_modifier_yangshi($str,$color="green",$size="16px")//至少一个形参 { $str = "<span style='color:{$color}; font-size:{$size}'>{$str}</span>"; return $str; } //注意文件命名书写方式
<?php function smarty_modifier_substr($str,$num=10,$end="...")//截取字符串,(要截取的字符穿,截取长度,后面用什么代替) { $str = substr($str,0,$num-3); //(要截取的字符串,开始位置,结束为止) $str = $str.$end; return $str; }
<?php function smarty_modifier_sexname($sex) { /*if($sex) { return "男"; } else { return "女"; }*/ return $sex?"男":"女"; }
<?php function smarty_modifier_nationname($nation) { $db = new MySQLi("localhost","root","root","mydb"); $sql = "select name from nation where code='{$nation}'"; $result = $db->query($sql); $attr = $result->fetch_row(); return $attr[0]; }