smarty模板引擎中变量及变量修饰器用法实例
《PHP实例:smarty模板引擎中变量及变量修饰器用法实例》要点: 本篇章节讲解smarty变量及变量修饰器的应用.分享给大家供大家参考.具体如下:PHP实战 模板文件:temp.htm:
代码如下:
{config_load file="foo.conf"}
{$name.na1|cat:$name['na2']} {$name['na1']|cat:'与'|cat:$name.na2} {foreach from=$name item=na} {$na} {/foreach} {$dog->leee()}{$dog->name} <script> {literal} function foobar{ ?alert('foobar!'); } {/literal} </script> <title>{#pageTitle#}</title> <body bgcolor="{#bodyBgColor#}"> <table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}" > ?<tr bgcolor="{#rowBgColor#}"> ? <td>dosomething</td> ? <td>帅锅</td> ?</tr> </table> {$smarty.server.SERVER_NAME} <hr /> {$str|count_words} <hr /> -------常量--------<br> {$smarty.now}<br />{$smarty.const.MY_CONST}<br />{$smarty.template}<br />{$smarty.current_dir}<br />{$smarty.version}<br />{$smarty.ldelim|cat:$smarty.rdelim} <hr /> {$smarty.now|date_format:$config} {$yesterday|date_format:'Y-m-d'} <hr /> {$string|default:'default变量修饰:smarty学习'} <hr /> {$str1|escape:'html'}<br />{$str2|escape:'mail'} <hr /> <p>{$str1|indent|upper}</p> {$str1|nl2br} <hr /> {$str1|regex_replace:"/@d{3}/":"ABC"}<br /> {$str1|replace:"163":"sina"}<br /> {$str1|spacify}<br /> <hr /> {$number|string_format:"%.2f"}<br /> {$number|string_format:"%d"}<br /> <hr /> {$str3|strip:"|"}<br /> 去除包含在<>之间的字符:{$str3|strip_tags}<br /> 截取长度:{$str3|truncate:10:"...":true}<br /> 按长度换行:{$str3|wordwrap:30:"<br />"} <hr /> {append var='name' value="Bob" index="first"} {append var='name' value="John" index="last"} {$name.last}<br /> {foreach from=$family item=home} {foreach from=$home item=person} {$person} {/foreach} {/foreach} {$family[1].girl} <hr /> {assign var="name" value="张三丰"} {$name} </body> php文件:index.php
代码如下:
<?php
require_once('libs/Smarty.class.php'); $smarty = new Smarty(); $smarty->setTemplateDir($_SERVER['DOCUMENT_ROOT']."/php/templates/"); $smarty->setCompileDir($_SERVER['DOCUMENT_ROOT']."/php/templates_c/"); $smarty->setCacheDir($_SERVER['DOCUMENT_ROOT']."/php/cache/"); $smarty->caching = false; $arr = array("na1"=>"帅锅","na2"=>"美女"); $smarty->assign("name",$arr); class Dog{ //$str = "hello world,i am here. i love smarty!"; $config = "Y-m-d H:i:s"; //append成员办法的使用 希望本文所述对大家的php程序设计有所赞助.PHP实战 《PHP实例:smarty模板引擎中变量及变量修饰器用法实例》是否对您有启发,欢迎查看更多与《PHP实例:smarty模板引擎中变量及变量修饰器用法实例》相关教程,学精学透。编程之家 52php.cn为您提供精彩教程。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |