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>[email protected]";
$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>

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

结果:



发布了47 篇原创文章 · 获赞 25 · 访问量 29万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章