smarty之Hello world!
来源:互联网 发布:透明不干胶贴纸淘宝 编辑:程序博客网 时间:2024/06/06 08:40
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
<?phpinclude_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
- smarty之Hello world!
- hibernate之Hello world
- Spring之Hello World
- Lucene之Hello world
- DWR之HELLO world
- JNI 之 hello world
- ISAPI之Hello world
- Spring之Hello World
- ACE之hello world
- Hello,world之Erlang
- DWR之 Hello world
- android之Hello World!
- Android之Hello World
- lemon之Hello World
- Qt之hello world
- Ruby之Hello World
- ACE之hello world
- Lucene 之 Hello world
- 题目1193:矩阵转置
- 利用WPF创建含多种交互特性的无边框窗体
- 属于自己的,才是最真实的收获
- 送分啦
- php采集
- smarty之Hello world!
- Java 对象序列化
- Codeforce237-Div.2 A,B
- LightOJ数论题单及简易题解
- printf()输出格式控制
- CSS伪类与CSS伪元素的区别及由来
- MFC音乐播放器,界面漂亮,功能齐全+源码下载
- 编译ffmpeg的relocation R_X86_64_32 against错误
- Linux环境变量的设置和查看方法