All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
SQL循序渐进(21)更多的子查询_[SQL,Server教程]
ASP.NET,2.0打造购物车和支付系统之二_[Asp.Net教程]
如何实现Asp与Asp.Net共享Session_[Asp.Net教程]
C#教程:向注册表写入信息
C#中TreeView控件应用实例
在ASP.NET程序中值得注意的两个地方_.net资料_编程技术
ms,sql,更新表A中某列为表B中的值_mssql学习_编程技术
怎么将现有的网站过渡到XHTML_[Html教程]
.NET内置对象之Server对象_[Asp.Net教程]
PHP入门:什么是PHP-网站开发为什么选择PHP-_[PHP教程]
Reading number is top 10 pictures
清纯性感的美眉1
Sora aoi in China1
日本小萝莉2
So beauty, will let you spray blood3
China's first snake village2
Forced sex girl living abroad2
Sell the barbecue as says father du breul2
粉红蕾丝的美女
A man's favorite things8
Embarrassing things comic collection1
Download software ranking
Tram sex maniac 2 (H) rar bag17
网络管理员第三版
DreamWeaver8
尖东毒玫瑰A
Tram sex maniac 2 (H) rar bag16
The Bermuda triangle3
The king of fighters 97(Mobile phone games-apk)
apache-tomcat-6.0.33
Tram sex maniac 2 (H) rar bag8
Red cliff
aaa published in(发表于) 2013/12/24 5:50:42 Edit(编辑)
PHP技巧:详解phplib模板使用过程及运行原理_php资料_编程技术

PHP技巧:详解phplib模板使用过程及运行原理_php资料_编程技术

PHP技巧:详解phplib模板使用过程及运行原理_php资料_编程技术-你的首页-uuhomepage.com

详解phplib模板使用过程及运行原理

index.htm文件内容:






{SortList}






index.php内容:

$t->set_file ("Index", "index.htm");
$t->set_block("Index", "RowSort", "RowsSort");
..............................................
.................$list_sort...................
$t->set_var("SortList", $list_sort);
$t->parse("RowsSort", "RowSort", true);
..............................................
..............................................
$t->parse("OUT", "Index");
$t->p("OUT");
?>

详细分析过程:

一、$t->set_file ("Index", "index.htm"); $this->file[index] = index.htm


二、$t->set_block("Index", "RowSort", "RowsSort");

1、载入index文件index.htm内容并赋给变量$this->varvals[index]
2、$str = $this->varvals[index]获取模板文件内容
3、用preg_match_all函数来匹配模板文件中对应的block(RowSort)里的内容,并存储到$m[1][0]中
4、涯0逦募卸杂Φ腷lock(RowSort)里的内容(包括头和尾)替换为{RowSort}
5、变量$this->varvals[RowSort] = $m[1][0] , $this->varkeys[RowSort] = /{RowSort}/
6、变量$this->varvals[index] = $str(内容已发生改变,见第4步) , $this->varkeys[index] = /{index}/


三、$t->set_var("SortList", $list_sort);

设置$this->varvals[SortList] = $list_sort
设置$this->varkeys[SortList] = /{SortList}/


四、$t->parse("RowsSort", "RowSort", true);(此操作根据sort大小重复进行)

1、利用subst函数把$this->varvals数组中的所有变量值对其中可能含有的特殊字符\和$进行处理(\和$分别替换为\\和\$,这样可以确保下一步的preg_replace不出现意外),并赋给$varvals_quoted数组
2、$str = $this->varvals[RowSort]
3、我们可以看出此时$str中含有一个{SortList},而由三:$this->varkeys[SortList] = /{SortList}/,$this->varvals[SortList] = $list_sort
4、可见经过preg_replace我们得到的$str是已经解析了PHP模板变量{SortList}之后的内容了,返回$str
5、给$this->varvals[RowSort]进行延续赋值 //这里有个问题大家可能会考虑到就是显示的时候最开始那个{RowSort}未被解析,不用担心,phplib有finish函数会对它根据你的要求进行处理


五、$t->parse("OUT", "Index");

1、可以看出,这时$this->varvals[index]中有一个PHP模板变量要进行解析,即{RowSort}
2、而在前面几步中,我们已经把$this->varvals[RowSort]的内容解析好
3、这样以来,我们把全部PHP模板变量均已解析后的内容赋给变量$this->varvals[OUT]

六、$t->p["OUT"];

显然phplib中p函数即为输出函数,我们直接把$this->varvals[OUT]输出即可
//这里要注意的是输出之前有个phplib自动进行的动作,就是对未被解析的PHP模板变量根据你的要求进行处理.






添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.