时间:2021-07-01 10:21:17 帮助过:2人阅读
模板文件: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}
dosomething | 帅锅 |
{$str1|indent|upper}
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{
public $name;
public $age;
function leee(){
return $this->name."在干吗";
}
}
$dog = new Dog();
$dog->name="小狗";
$smarty->assign("dog",$dog);
//$str = "hello world,i am here. i love smarty!";
$str = "帅锅";
$str1 = "新浪 And\n aassu@163.com";
$str2 = "aassu@163.com";
$smarty->assign("str",$str);
$smarty->assign("str1",$str1);
$smarty->assign("str2",$str2);
$smarty->assign("number",30.293934);
$smarty->assign("str3","akie abfal ,dooerw,show databases,desc table");
$config = "Y-m-d H:i:s";
$smarty->assign("config",$config);
$smarty->assign("yesterday",strtotime('-1 day'));
//常量
define("MY_CONST","百度");
//append成员方法的使用
$family = array("husband"=>"帅锅","wife"=>"美女");
$famiadd = array("boy"=>"张三丰","girl"=>"王昭君");
$smarty->append("family",$family);
$smarty->append("family",$famiadd);
echo "
";
print_r($family);
$smarty->display("temp.htm");
?>希望本文所述对大家的php程序设计有所帮助。