smarty、smarty格式化、smarty整数、smarty float、smarty各种转换方式、smarty日期转换等等

来源:互联网 发布:windows禁止arp 编辑:程序博客网 时间:2024/06/05 11:33
<?
require("setup.php");
define('PAGETITLE','pagtitle');
function insert_top($lid,$sid)
{
echo "insert function";
}
$smarty=new SmartyRebuild();
$smarty->assign('name','Linux');
$smarty->assign('title','在线有有要有和蔼是是非非要要');
$smarty->assign('english_word','my name x4 is linux');
$smarty->assign('money','344.2223');
$smarty->assign('member',array('fax'=>'010-95888484','email'=>'linux@admin.com',
     'phone'=>array('home'=>'8488484','mobil'=>'5325325325353')));
$tempMember=array();
$tempMember['member']='dsgads';
$tempMember["phone"]["home"]="444333";
$contacts=array();
$contacts[]["fax"]="435454";
$contacts[]["phone"]="223523523";
$contacts[]["fax"]="42532532";
$contacts[]["phone"]="7888888";
$contacts2=array(array('fax'=>'32523','phone'=>'325132532'),array('fax'=>'2313532','phone'=>'325325132523'));
$contacts3=array();
$contacts3[0]="23523";
$contacts4=array();
$contacts4[0][0]="23523";
$contacts4[0][1]="23523";
$contacts3[1]="23523";
$contacts4[1][0]="23523";
$contacts4[1][1]="23523";
$contacts3[2]="23523";
$contacts4[2][0]="23523";
$contacts4[2][1]="23523";
$contacts3[3]="23523";
$contacts4[3][0]="23523";
$contacts4[3][1]="23523";
$smarty->assign('contacts',$contacts);
$smarty->assign('contacts2',$contacts2);
$smarty->assign('contacts3',$contacts3);
$smarty->assign('contacts4',$contacts4);
$smarty->assign('tempmember',$tempMember);
$smarty->display('index.tpl');
?>



smarty code:

     

{config_load file='config.conf'}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <TITLE>Smarty学习</TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
</HEAD>

<BODY>
{capture name=banner}{*注释掉中间显示内容*}
{include file="banner.tpl"}
{/capture}
{include file="banner.tpl" title="Smarty学习"}
{$smarty.get.page}<br/>
{$smarty.post.page}<br/>
{$smarty.cookies.name}<br/>
{$smarty.server.SERVER_NAME}<br/>
{$smarty.env.PATH}<br/>
{$smarty.session.id}<br/>
{$smarty.request.username}<br/>
{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}<br/>
{$smarty.const.PAGETITLE}{*常量*}<br/>
Hello {$name}{*变量*}<br/>
{html_select_date display_days=yes}<br/>
{$member.fax}<br/>
{$member.phone.home}<br/>
{$tempmember.member}<br/>
{$tempmember.phone.home}{*多维数组*}<br/>
{#error_message#}{*配置文件属性*}<br/>
{$name|lower}{*smarty字符串函数*}<br/>
{$name|upper}{*smarty字符串函数*}<br/>
{'now'|date_format:'%Y-%m-%d'}{*smarty日期函数*}<br/>
{$title|truncate:11:"..."}{*截断字符串超长加...*}<br/>
{mailto|lower address="mailto:linux@admin.com%22%7D%7B*mailto邮件*}<br/>
mailto:%7B$tempmember%7C@count}{*数据的总和*}<br/>
{$english_word|capitalize}{*首字母大写*}<br/>
{$english_word|capitalize:true}{*每个单词的首字母大写*}<br/>
{$title|count_characters:true}{*字符串的长度加true字符空格,不加true不计算空格*}<br/>
{$title|cat:'字符串后加入字符'}{*拼接字符串*}<br/>
{$title|count_words}{*计算字符数量*}<br/>
{$title2|default:"dsgadsgds"};{*如果变量不存在就输出默认值*}<br/>
{$english_word|escape:html}{*将字符串中的HTML转换为HTML编码方式*}<br/>
{$english_word|escape:htmlall}{*将字符串中的HTML转换为HTML编码方式*}<br/>
{$english_word|escape:url}{*将字符串中的HTML转换为URL编码方式*}<br/>
{$english_word|escape:quotes}{*将字符串中的HTML转换为HTML编码方式*}<br/>
{$title|indent:100}{*缩进指定宽度*}<br/>
{$title|regex_replace:"/要/":"爱"}{*正则表达式替换字符*}<br/>
{$title|replace:"要":"爱"}{*Replace替换字符*}<br/>
{$english_word|spacify:"||"}{*分隔字符串*}<br/>
{$money|string_format:"%.2f"}{*格式化数字为Float数*}<br/>
{$money|string_format:"%d"}{*格式化数字为INT数*}<br/>
{$english_word|strip:" "}{*替换空格*}<br/>
{$english_word|strip_tags:false}{*替换标签*}<br/>
{$english_word|truncate:10:"..."}{*截取指定长度字符,默认截取80字符长度*}<br/>
{$english_word|wordwrap:10}{*多长后字符串换行,默认换行长度为80*}<br/>
{$english_word|upper|spacify|truncate:30:"..."}{*Smarty支持多个函数的组合,此组合为字符串先大写然后分隔然后截取指定长度*}<br/>
{foreach name=outer item=contact from=$contacts}{*foreach循环数组*}
  {foreach key=key item=item from=$contact}
  {$key}:{$item}<br/>
  {/foreach}
{/foreach}
{foreach name=outer item=contact2 from=$contacts2}
  {foreach key=key item=item from=$contact2}
  {$key}:{$item}<br/>
  {/foreach}
{/foreach}
{include_php file="function.php"}{*包含指定的PHP文件*}
{insert name="top" lid="toplid" sid="topsid"}{*调用insert_top PHP函数,函数参数为lid和sid的值*}
{if 1 eq 1}{*条件判断语句*}
  1=1
{elseif 1 ne 1}
  1!=1
{elseif 1 gt 1}
  1>1
  {elseif 1 lt 1}
  1<1
  {elseif 1 gte 1}
  1>=1
  {elseif 1 lte 1}
  1<=1
  {elseif not 1 eq 1}
  not 1=1
  {elseif (1 mod 1) eq 1}
  <font color="red">1%1=1</font>
  {else}
  你的人品真不好
  {/if}
{ldelim}function insert_top {rdelim} is insert_top {*输出中括号*}
{literal}{*加入一段HTML,脚本代码等*}
<script language="javascript" type="text/css">
<!--
function load()
{
  alert('页面加载....');
}
//-->
</script>
  {/literal}
  {*包含一段PHP语句*}
  {php}
  echo "php代码运行";
  {/php}
  {section name=member loop=$contacts3 show=true}{*while循环 show是否SHOW section中的循环内容*}
   {if $smarty.section.member.first}
  first
{/if}
{if $smarty.section.member.last}
  last
{/if}
current loop rownum:{$smarty.section.member.rownum}<br/>
   current loop iteration:{$smarty.section.member.iteration}<br/>
   index:{$smarty.section.member.index} index_prev:{$contacts3[member.index_prev]} index_next:{$contacts3[member.index_next]} index:{$contacts3[member.index]} member:{$contacts3[member]}
   {section name=memberchild loop=$contacts4[member] max=2}
    memberchild:{$contacts4[member][memberchild]}
   {/section}
   total:{$smarty.section.member.total}{*数据长度或总记录数*}
  {/section}

</BODY>
</HTML>
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 淘宝账号不小心注销了怎么办 淘宝旧密码忘了怎么办 淘宝登录原始密码忘记了怎么办 微信原始密码忘记了怎么办 优酷会员重复交费怎么办 微信解绑手机号密码忘了怎么办 闪银呼呼逾期5天怎么办 忘记淘宝账号和密码怎么办 蘑菇街账号忘了怎么办 台式电脑密码忘记了怎么办 单位社保登陆密码忘记了怎么办 12306的登录密码忘了怎么办 网银支付密码忘了怎么办 邮政网银密码忘了怎么办 12306新注册待核验怎么办 建行网银盾密码忘了怎么办 建行网银登陆密码忘了怎么办 建行网银密码忘了怎么办 建行手机网银密码忘了怎么办 移动宽带账号密码忘了怎么办 移动宽带忘记账号密码怎么办 宽带账号密码忘了怎么办 不知道宽带账号密码怎么办 宽带的账号密码忘记了怎么办 wifi登录名忘记了怎么办 苹果手机微信图纸打不开怎么办 手机qq邮箱文件打不开怎么办 12360忘记用户名和密码怎么办 刚开店铺没生意怎么办 淘宝账户不符合注销条件怎么办 网易邮箱登录密码忘记了怎么办 q号密码忘记了怎么办 志愿者注册忘记密码和用户名怎么办 w10电脑语言栏不见了怎么办 w10美式键盘没了怎么办 xp电脑开机密码忘记了怎么办 电脑开机密码到期忘记改怎么办 电脑账户数据库密码忘了怎么办 微信不能拍摄了怎么办 华硕笔记本用户名密码忘了怎么办 学信网登录密码用户名搞忘怎么办