smarty 输出主机名等
1 <?php 2 header("Content-type: text/html; charset=utf-8"); 3 //设置中国时区 4 date_default_timezone_set('PRC'); 5 6 require_once("./Smarty/libs/Smarty.class.php"); 7 $smarty = new Smarty(); 8 $smarty->left_delimiter="<{"; 9 $smarty->right_delimiter="}>"; 10 $smarty->assign("name","张三丰"); 11 $smarty->assign("age",24); 12 define("DB_HOST","localhost"); 13 14 $smarty->display("./view.html"); 15 16 echo "<br>-----Program is Over-----";
view.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>view视图文件</title>
</head>
<body>
姓名:<{$name}><br>
年龄:<{$age}><br>
主机名:<{$smarty.const.DB_HOST}><br>
最大整数:<{$smarty.const.PHP_INT_MAX}><br>
PHP时间戳:<{time()}><br>
Smarty时间戳:<{$smarty.now}><br>
PHP date:<{date("Y-m-d H:i:s")}><br>
Smarty时间:<{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}><br>
</body>
</html>

浙公网安备 33010602011771号