如果你从来没有接触过PHP,那么还是先看看这个吧,当然即使是你已经对PHP有所了解,但一本PHP4的的使用手册也还是需要的,:)。此外一本HTML语法手册当然也是不可缺少的啦。。。。。。。。。。
在网站开发过程中你是不是经常面对改版的苦恼?几百几千个文件因为版式上的一点小变化就需要全部重新处理,是不是让你头痛无比?唉,如果能够把内容和表现形式分开就好了,这可是我们一直翘首等待的。但可惜用于处理这个问题的XML还未完全的成熟。难道除此之外就没有办法了吗?正所谓东西是死的,人却是活的,我们今天要学习的这个PHP库,就可以帮助我们在一定程度上处理这个问题。:))
FastTemplate是什么?从PHP语言上来讲它是一个PHP库;从它的起源来说它源于一个同样名称的Perl软件包;从用途上来讲是一个可以让你在几秒内改变整个站点外观的实用工具。用最通俗的语言来说,它就是一个模板,一个类似DreamWaver中的模板。现在FastTemplate在你心里是一个问号?还是一个感叹号?又或是一个句号?(编辑:靠,在这骗稿费呀,我扁!)算了,不管那么多,你只要知道他是好东西就成,:)
首先在我们使用这个库以前当然要先下载它(编辑:'废话,又骗稿费啊' 。地藏:'好吧,好吧,我不说了。:( '。),大家可以在下面这个网址http://www.thewebmasters.net/PHP/下载它。下载之后呢把它解压缩到你的web服务器的一个目录上,下面是解压缩后的目录结构
FastTemplate-1.1.0/
FastTemplate-1.1.0/README < - 这个文件就不用说了吧?
FastTemplate-1.1.0/class.FastTemplate.PHP3 < - 这个文件最重要,它就库文件,核心耶!
FastTemplate-1.1.0/example_1.phtml < - 一个例子
FastTemplate-1.1.0/example_2.phtml < - 第二个例子
FastTemplate-1.1.0/example_3.phtml < - 第三个例子
FastTemplate-1.1.0/dynamic_example.phtml < - 第四个例子
FastTemplate-1.1.0/docs/ < - 文档目录
FastTemplate-1.1.0/docs/FastTemplate.3 < - Unix man page
FastTemplate-1.1.0/docs/FastTemplate.html < - HTML documentation
FastTemplate-1.1.0/templates/ < - 模板例子的目录
FastTemplate-1.1.0/templates/begin.tpl
FastTemplate-1.1.0/templates/header.tpl
FastTemplate-1.1.0/templates/main.tpl
FastTemplate-1.1.0/templates/row.tpl
FastTemplate-1.1.0/templates/test.tpl
FastTemplate-1.1.0/templates/footer.tpl
FastTemplate-1.1.0/templates/htaccess.tpl
FastTemplate-1.1.0/templates/middle.tpl
FastTemplate-1.1.0/templates/table.tpl
注意哟,这个目录一定要是PHP程序可以访问的目录哟,换句话说就是PHP.ini里那个include目录。然后呢,使用PHP4编程的朋友注意了,你现在还不能直接使用这个库,还需要人工做些修改!等下注意看下面。PHP3的读者就不用管那么多,现在就可以试一下它带的那几个例子了,(嘿嘿,不过呢,它那些例子的后缀名全是phtml,如果你没办法设置web的话。你可以尝试把后缀名改改看,应该也可以用,地藏没有试过不敢打包票。)那!接着呢,PHP4的兄弟可千万要注意哟,如果不你不按下面的修改的话,这个库可是没有办法用的哟!!
--- class.FastTemplate.PHP3 Sun Jun 27 13:44:47 1999
+++ PHP4.FastTemplate.PHP3 Tue Jul 20 10:49:25 1999
@@ -196,8 +196,10 @@
settype($val,"string");
}
- $template = ereg_replace("{$key}","$val","$template");
- //$template = str_replace("{$key}","$val","$template");
+ // PHP4 doesn't like '{$' combinations.
+ $key = '{'."$key".'}';
+ $template = ereg_replace("$key","$val","$template");
+ //$template = str_replace("$key","$val","$template");
}
}
@@ -410,7 +412,7 @@
}
if($end)
{
- $newParent .= "{$MacroName}
";
+ $newParent .= '{'."$MacroName}
";
}
// Next line please
if($end) { $end = false; }
大家用文本编辑器打开class.FastTemplate.PHP3文件,找到上面的部分。'-'减号代表消除这行,'+'加号代表加入这行。另外windows系统下的朋友注意哟!你们还需要改点小东西,把下面的那个$win32变量的值改成true,不改的话,用不了可别骂我,;)。
var $WIN32 = true; // Set to true if this is a WIN32 server
改好后,大家就可以试试他的那几个例子了。 如何?成功了吧。嘿嘿嘿嘿~~~,地藏不会骗大家的啦。
OK,现在这个库已经可以用啦,我们准备进行下面的学习吧,:)
如何使用这个库?简单哟,首先要把这个库包含进来。也就是说呢,要 include "class.FastTemplate.PHP3"; 然后?呵呵…… 然后我也不知道啦!(编辑:"嘿!找扁啊,你!")啊,啊…!Sorry,我想起来了(在地藏被众编辑海扁一顿之后)。然后是学习这个库的使用原理。在这里呢我们先做个假设。
我们假设一个页面是由很多的小的部分组成(比如:每个网站都有分栏目导航等等),而且每个小的部分都有一个唯一的标识符(比如:我们把分栏每个小项定义为一个名字)
我们首先以这个库自带的example_1为例,让大家可以尽快的学会这个库的基本用法,;),不过大家要注意哟,这几个文件在服务器上的位置要按解压时的相对路径来存,千万不要忘记,就象不要忘记你女朋友的生日一样。呵呵~~~~
< ?
// Example FastTemplate Demo #1 - The example from the man page
Header("Content-type: text/plain");
include("class.FastTemplate.PHP3");
$tpl = new FastTemplate("./templates");
$tpl- >define(
array(
main = > "main.tpl",
table = > "table.tpl",
row = > "row.tpl"
)
);
$tpl- >assign( array( TITLE = > "FastTemplate Test") );
for ($n=1; $n < = 3; $n++)
{
$Number = $n;
$BigNum = $n*10;
$tpl- >assign(
array(
NUMBER = > $Number,
BIG_NUMBER = > $BigNum
)
);
$tpl- >parse(ROWS,".row");
}
$tpl- >parse(MAIN, array("table","main"));
$tpl- >FastPrint();
exit;
? >
< !-- NAME: main.tpl -- >
< html >
< head >< title > {TITLE} < /title >
< /head >
< body >
{MAIN}
< /body >
< /html >
< !-- END: main.tpl -- >
< !-- NAME: table.tpl -- >
< table border='1' >
{ROWS}
< /table >
< !-- END: table.tpl -- >
< !-- NAME: row.tpl -- >
< tr >
< td >{NUMBER}< /td >
< td >{BIG_NUMBER}< /td >
< /tr >
< !-- END: row.tpl -- >
使用这个库首先要如前面所说的 include "class.FastTemplate.PHP3"; 然后是定义模板所在目录$tpl = new FastTemplate("./templates");注意哟!这里因为我是在windows系统运行,所以用的是"./templates",在Linux或UNIX中可能不一样,大家根据具体情况来设定。然后呢,我们对应不同的模板,定义下面这个矩阵数组。$tpl- >define( array( main = > "main.tpl", table = > "table.tpl", row = > "row.tpl" ) ); define 共2页: 上一页 1 [2] 下一页 <script type="text/javascript">
</script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
实例学习PHP之FastTemplate 模板篇
最新推荐文章于 2021-06-05 04:28:16 发布
<script type="text/javascript">
</script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript">
</script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript">
</script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>