<?
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>

smarty、smarty格式化、smarty整数、smarty float、smarty各种转换方式、smarty日期转换等等 (转)的更多相关文章

  1. php Smarty date_format [格式化时间日期]

    Example 5-8. date_format[日期格式] index.php: 复制代码代码如下: $smarty = new Smarty; $smarty->assign('yester ...

  2. smarty 时间格式化date_format

    代码如下:$smarty = new Smarty; $smarty->assign('yesterday', strtotime('-1 day')); $smarty->display ...

  3. Number 强制类型转换 int 强制转换整型 float 强制转换浮点型 complex 强制转换成复数 bool 强制转换成布尔类型,结果只有两种,要么True 要么 False """bool 可以转换所有的数据类型 everything"""

    # ###Number 强制类型转换 var1 = 5 var2 = 4.85 var3 = True var3_2 = False var4 = 3+9j var5 = "888777&q ...

  4. Shell中整数自增的几种方式

    Shell中整数自增的几种方式 2016年08月27日 19:07:40 杰瑞26 阅读数:2816    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.n ...

  5. MySQL日期函数与日期转换格式化函数大全

    Mysql作为一款开元的免费关系型数据库,用户基础非常庞大,本文列出了MYSQL常用日期函数与日期转换格式化函数 1.DAYOFWEEK(date) 1 2 SELECT DAYOFWEEK('201 ...

  6. smarty模板配置代码详细说明及如何注册自己的smarty函数

    下面为smarty模板的配置文件,smarty配置的详细说明以及如何注册自己所需要的smarty函数 config.inc.php <?php /** * Smarty 调用 * www.daf ...

  7. python:格式化输出整数

    import math #default print "PI = %f" % math.pi #width = 10,precise = 3,align = left print ...

  8. 笔试题引出float数据的存储方式的深究

    笔试题: #include <iostream>#include <stdio.h>#include <string.h>#include <conio.h& ...

  9. 浮点数float累加误差解决方式总结

    首先是float累加产生误差的原因,该部分转自:http://blog.csdn.net/zhrh0096/article/details/38589067 1.  浮点数IEEE 754表示方法 要 ...

随机推荐

  1. Laravel使用db:seed生成测试数据

    创建 生成数据 定义字段 call方法调用 执行 seeder里如有多个可指定class 整理自www.laravist.com 视频教程

  2. HDU 6298.Maximum Multiple-数学思维题(脑子是个好东西,可惜我没有) (2018 Multi-University Training Contest 1 1001)

    暑假杭电多校第一场,这一场是贪心场,很多贪心的题目,但是自己太菜,姿势挫死了,把自己都写吐了... 2018 Multi-University Training Contest 1 HDU6298.M ...

  3. Codeforces 954H Path Counting(DP)

    题目链接  Path Counting 题意  给定一棵高度为$n$的树,给出每一层的每个点的儿子个数(某一层的所有点儿子个数相同).   令$f_{k}$为长度为$k$的路径条数,求$f_{1}, ...

  4. poj1743(后缀数组)

    poj1743 题意 给出一个数字序列(串),现在要去寻找一个满足下列条件的子串: 长度不小于 5 存在重复的子串(如果把一个子串的所有数字都加上或减去一个值,与另一子串的数字对应相同,我们称它们重复 ...

  5. 数论day1 —— 基础知识(们)

    [pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=61632537 向大(hei)佬(e)势力学(di ...

  6. [LOJ6277]数列分块入门 1

    题目大意: 给你一个长度为$n(n\leq 50000)$的序列$A$,支持进行以下两种操作: 1.将区间$[l,r]$中所有数加上$c$: 2.询问$A_r$的值.思路: 分块. 对于整块的数据打标 ...

  7. iOS开发 Swift开发数独游戏(三) 选关界面

    一.选关界面涉及到的功能点 1)需要UITableView以及相应数据代理.协议的实现 2)读取plist文件并转化成模型 3)在单元格点击后进入数独游戏,涉及到把数据经segue在UIViewCon ...

  8. eclipse无法导入Android工程的解决办法

    我以前在windows平台下写的android源代码无法通过import"existing project into workspace"导入到mac的eclipse中,直接搜不见 ...

  9. apache 返回的状态码304

    博客转载:http://baike.baidu.com/link?url=jhw62dpK66WD7EQFKWEhVQs_jPeFKIUegnA6 如果客户端发送了一个带条件的GET 请求且该请求已被 ...

  10. EarlyZ disable( earlyz失效

    There are a few ways to disable EarlyZ list here: Shader depth output disabled Alpha test with depth ...