Smarty变量调节器的使用

$str = 'how Are you';
$smarty->assign('str', $str);

$title = "\nbbbbbb。bbbb\n1111111\nbbbbbbbb\n222.\t22.22";
$smarty->assign('title',$title);

$name = "who are \n you?";
$smarty->assign('name',$name);

$address = "<center>I'm center</center><sm>ddddddd</sm>";
$smarty->assign('address',$address);

$leg = "1a2 admin b3c4d5e6g7h8i9j";
$smarty->assign('leg',$leg);

$file = "hi who are you where are from";
$smarty->assign('file',$file);

$num = 123.4567;
$smarty->assign('num',$num);

$content = "hit me <a href='#'>this is a test</a><?c=admin&a=input>aaa@admin.com";
$smarty->assign('content',$content);

$smarty->display('index.html');		//显示index.html

html

<{$str}><br>
<{$str|capitalize}><{*首字母大写*}><br>
<{$str|upper}><{*全部大写*}><br>
<{$str|lower}><{*全部小写*}><br>
<{$str|lower|upper}><{*全部大写,调节从左至右*}><br>
<{$str|count_characters}><{*统计字符的个数*}><br>
<{$str|count_characters:true}><{*统计字符的个数,包括空格*}><br>
<{$str|cat:"??????"}><{*连接到变量的值后面*}><br><br>

<{$title|count_paragraphs}><{*统计变量中段落的个数,即相邻\n或\r的会算为一个*}><br>
<{$title|count_sentences}><{*统计变量中句子的个数*}><br>
<{$title|count_words}><{*统计变量中单词的个数*}><br><br>

<{$smarty.now|date_format:"%Y-%m-%d %p %H:%M:%S week:%W"}><{*当前时间2012-04-25 AM 08:20:17 week:17*}><br><>br

<{$user|default:"null"}><{*如果变量为空或者不存在时,输出默认的值,即default的值*}><br><br>

<{$name}><br>
<{$name|indent}><br>
<{$name|indent:10}><br>
<{$name|indent:1:"\t"}><br><br>

<{$name|regex_replace:"/[\r\n\t]/":"string"}><{*正则替换*}><br><br>

<{$name|replace:"who":"where"}><{*替换*}><br><br>

<{$name|spacify:"!"}><{*在字符之间插入字符*}><br><br>

<{$name|strip}><{*用空格或指定字符替换所有重复空格、换行、制表符*}><br>
<{$name|strip:" "}><br><br>

<{$address}><br>
<{$address|strip_tags}><{*去掉<>标签及中间的内容*}><br><br>

<{$leg|truncate}><{*字符串截取,默认80个字符*}><br>
<{$leg|truncate:10}><{*字符串截取,前10个,包括...三个字符*}><br>
<{$leg|truncate:10:""}><{*字符串截取,前10个字符,不用...代替后面的内容*}><br>
<{$leg|truncate:10:"---"}><{*字符串截取,前10个字符,以单词结束,用---代替后面的内容*}><br>
<{$leg|truncate:10:"...":true}><{*字符串截取,前10个字符,精确个数,用...代替后面的内容*}><br>
<{$leg|truncate:10:"":true}><{*字符串截取,前10个字符,不用...代替后面的内容*}><br><br>

<{$file}><br>
<{$file|wordwrap:10}><{*10字符为一行*}><br>
<{$file|wordwrap:10:"<br>\n"}><{*10字符为一行*}><br>
<{$file|wordwrap:10:"\n":true}><{*10字符为一行*}><br><br>


<{$num}><br>
<{$num|string_format:"%.2f"}><{*取两位小数,四舍五入*}><br>
<{$num|string_format:"%d"}><{*取整*}><br><br>


<{$content}><br>
<{$content|escape}><br>
<{$content|escape:"html"}><br>
<{$content|escape:"htmlall"}><br>
<{$content|escape:"url"}><br>
<{$content|escape:"quotes"}><br>
<{$content|escape:"hex"}><br>
<{$content|escape:"hexentity"}><br>
<{$content|escape:"javascript"}><br>

变量调节器,可以组合使用,来达到显示的效果,用"|"分隔,从左到右执行

结果:



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值