标签:
<?php
require_once ‘inc/libs/Smarty.class.php‘;
$s=new Smarty();
// echo $s::SMARTY_VERSION;
// echo smarty::SMARTY_VERSION;//输出版本号
$s->debugging=false;
$s->setTemplateDir(‘html‘);
$s->assign(‘title‘,‘我的网页‘);
$s->assign(‘address‘,[‘郑州‘,‘北京‘,‘上海‘]);
class st{
public $name="jack";
public $age=20;
public $address="郑州";
}
$st=new st();
$s->assign(‘st‘,$st);
$s->display(‘index.html‘);
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>网站首页</title>
</head>
<body>
<h1>显示学生姓名:{$st->name}</h1>
<h1>{$title}</h1>
<hr>
{*模板的注释语句 *}
{foreach $address as $k=>$v}
{$v}<br>
{foreachelse}
没有数据循环
{/foreach}
</body>
</html>
{foreach $num as $k=>$v}
<span style="color:{cycle values=‘green,red,yellow‘}">
{$v}----{$k}---{$v@index}---{$v@first}
---{$v@last}---{$v@total}---{$v@iteration}<br>
</span>
{foreachelse}
没有循环数据输出
{/foreach }
class st{ //创建类并读出来
public $name="jack";
public $age=20;
public $address="郑州";
}
$st=new st();
$s->assign(‘st‘,$st);
<h1>显示学生姓名:{$st->name}家庭住址:{$st->address}学生年龄{$st->age}岁</h1>
//pdo 查询显示数据
include ‘Db.class.php‘;
$db = new Db();
$s->assign(‘stu‘,$db->query(‘pro‘,‘title,img‘));
{foreach $stu as $v}
{$v@iteration}、{$v[‘title‘]}<br>
{foreachelse}
没有数据读出
{/foreach}
{counter}、kljfdsj<br>
{counter}、dsfksldjf<br>
{counter}、dskf<br>
{counter}、kljfdsj<br>
{counter name=aa skip=1 start=10}、郑州<br>
{counter name=aa}、北京<br>
{counter name=aa}、上海<br>
{counter name=aa}、天津<br>
{foreach $stu as $v}
{$v@iteration}、{$v[‘title‘]}===={$v[‘img‘]}<br>
{foreachelse}
没有数据读出
{/foreach}
{*模板文件中定义变量*}
{$age=20}
{$add=‘郑州‘}
{$love=[‘音乐‘,20]}
{$age}----{$add}----{$love[0]}//输出
{*直接调用函数*}
{date(‘Y-m-d H:i:s‘)}<br>
{time()|date_format:‘Y-m-d H:i:s‘}
{$smarty.get.id|default:1}
{$smarty.post.id|default:1}
{$smarty.request.id|default:1}
{$smarty.session.user|default:‘jack‘}
<script>
function aa(){
alert(‘ok‘);
}
aa();
</script>
<script>
function aa(){alert(‘ok‘);}
aa();
</script>
{literal}
<script>
function aa(){alert(‘ok‘);//不换行不能输出
}
aa();
</script>
{/literal}
$s->assign(‘title‘,‘aaa的水立方接收到了解放了圣诞节福利圣诞节疯狂两三点‘);
<h1>{$title|truncate:11:‘###‘}</h1>
<h1>{$name=‘打了飞机冻死了房间里撒大家分开了圣诞节分类考试大姐夫‘}</h1>
<h1>{$name|truncate:10}</h1>
{$i=‘ok‘}
{$i|md5}
$s->assign(‘title‘,‘aaa的水立方接收到了解放了圣诞节福利圣诞节疯狂两三点‘);
<h1>{$title|default:‘未分配‘|upper|truncate:11}</h1>
{for $i=1 to 10}
{$i}
{/for}
{$n=1}
{while $n<10}
{$n++}
{/while}
include ‘footer.html‘;
{if 1==1 }
ff
{/if}
{$n=1}
{if 1==2}
{else}
yyyy
{/if}
{if 1==2}
2
{else if 1==3}
3
{else if 1==4}
4
{else}
5
{/if}
{capture assign="info"}
dsflsd<br>
dafd<br>
{time()}
{for $y}
{/capture}
{$info}
{for $i=1 to 50}
<div style="background-color:{cycle values=‘green,yellow,red,blue‘};margin:20px auto; width:600px;">{$i}</div>
{/for}
$s->assign(‘add‘,[‘hn‘=>‘河南省‘,‘sh‘=>‘上海‘,‘bj‘=>‘北京‘]);
$s->assign(‘adf‘,[‘河南省‘,‘上海‘,‘北京‘]);
{html_checkboxes name=‘id‘ options=$add selected=‘bj‘ separator=‘ ‘}<br>
{html_checkboxes name=‘id‘ output=$adf selected=[‘河南省‘,‘北京‘] values=$adf separator=‘ ‘}<br>
{html_radios name=‘id‘ output=$add selected=‘上海‘ values=$add separator=‘ ‘ }<br>
{html_options name=‘id‘ output=$add selected=‘上海‘ values=$add separator=‘ ‘ }<br>
{html_options name=‘id‘ options=$add selected=‘bj‘ values=$add separator=‘ ‘ }<br>
if($c==‘rand‘){
$cs=‘0123456789abcdef‘;
$ccc=‘#‘;
$ccc.=substr($cs, mt_rand(0,strlen($cs)-1),1);
$ccc.=substr($cs, mt_rand(0,strlen($cs)-1),1);
$ccc.=substr($cs, mt_rand(0,strlen($cs)-1),1);
$ccc.=substr($cs, mt_rand(0,strlen($cs)-1),1);
$ccc.=substr($cs, mt_rand(0,strlen($cs)-1),1);
$ccc.=substr($cs, mt_rand(0,strlen($cs)-1),1);
$c=$ccc;
}
<?php
function smarty_modifier_cc($string,$c=‘rand‘){
if($c==‘rand‘){
$cs=‘0123456789abcdef‘;
$ccc=‘#‘;
$ccc.=substr($cs, mt_rand(0,strlen($cs)-1),1);
$ccc.=substr($cs, mt_rand(0,strlen($cs)-1),1);
$ccc.=substr($cs, mt_rand(0,strlen($cs)-1),1);
$ccc.=substr($cs, mt_rand(0,strlen($cs)-1),1);
$ccc.=substr($cs, mt_rand(0,strlen($cs)-1),1);
$ccc.=substr($cs, mt_rand(0,strlen($cs)-1),1);
$c=$ccc;
}
return "<span style=‘color:$c‘>$string</span>";
}
{$title|cc}<br>
标签:
原文地址:http://www.cnblogs.com/lsr111/p/4612215.html