smarty之Hello world!

smarty是php的模板引擎,目的是分离业务逻辑和显示逻辑。


ok,下面举例怎么在项目中引入smarty。


1、下载smarty

http://www.smarty.net/download

注意php版本和smarty的匹配


2、解压smarty,把lib目录复制粘贴到网站根目录下,改名lib为smarty

3、在网站根目录创建文件夹templates和template_c

4、创建test.php

<?php
include_once("./smarty/smarty.class.php");
$smarty = new Smarty();
$smarty->template_dir = "./templates";   
$smarty->compile_dir = "./templates_c";
$smarty->left_delimiter = "{{";
$smarty->right_delimiter = "}}";
$smarty->assign('username','雨田');  
$smarty->display("test.html");
?>


5、在templates下面创建test.html

<!DOCTYPE html>
<html>
<head>
    <title>My First Page</title>
</head>
<body>
    My name is {{$username}}
</body>
</html


6、运行test.php

显示如下

My name is 闆ㄧ敯

咦,有乱码。。。。

解决乱码问题:

在test.php中加入

header("Content-Type:text/html;charset=utf-8");



ok,在运行下test.php,显示正常,乱码问题解决

My name is 雨田

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值