Upload
gwennan-parker
View
33
Download
6
Embed Size (px)
DESCRIPTION
UCHome 模板解析. Zuoyuan 2012/3/23. 问题提出. 为什么要了解模板? 模板解析的过程是什么样的? 模板的基本语法 怎样修改模板?. - PowerPoint PPT Presentation
Citation preview
1. <!--//说明 : 显示公共头部模板 -->2. <!--{template common/header}-->
3. <!--//说明 : 开始显示留言 -->4. <div id="ct" class="wp cl">5. <h1 class="mt"> 心情墙 - <!--{if $_G[uid]}--><a href="mood.php?mod=publish"> 发表心情</a><!--{/if}--></h1> 6. <div class="bm">7. <!--{if $list}-->8. <!--//说明 : loop 循环一个数组 相当于 foreach(){}-->9. <!--{loop $list $mood}-->10. <a href="home.php?mod=space&uid=$mood[uid]" target="_blank"><!--
{avatar($value[authorid],small)}--></a><br>11. <a href="home.php?mod=space&uid=$mood[uid]" title="$mood[username]" target="_blank"
class="xi2">$mood[username]</a> 发表于 : $mood[dateline]12. <br>13. 心情 : $mood[message]14. <hr>15. <!--{/loop}-->16. <!--//说明 : 显示准备好的分页链接 -->17. $multi18. <!--{else}-->19. <p class="emp"> 暂时没有记录 ...</p>20. <!--{/if}-->21. </div>22. </div>
23. <!--//说明 : 显示公共尾部模板 -->24. <!--{template common/footer}-->
正则表达式• 功能:字符串查找匹配• 类似的技术:通配符 windows 下的 * ?• 一个例子
在模板中查找 <!--{template 各种可用字符 }-->正则表达式是 \<\<\!\-\-\{template\s+ ([a-z0-9_\/]+)\}\-\-\>
正则表达式基本语法/ 定界符^ 字符串头$ 字符串尾[a-z] 所有小写字母[A-Z] 所有大写字母[0-9] 所有数字? 零或一个紧接前的字符* 零或多个紧接前的字符+ 一或多个紧接前的字符{4} 4 个紧接前的字符{4,8} 4-8 个紧接前的字符. 任意字符(red|green|blue) Red 或 green 或 blue (红 或 绿 或 蓝)s 空格( ) [ ] . * ? + ^ | $
正则表达式参考• http://
deerchao.net/tutorials/regex/regex.htm• 正则表达式入门经典 Andrew
watt(TP301.2/6)
UChome 模板的语法<!--{template common/header}-->用 common/header.htm 替换这里<!--{template common/footer}-->用 common/footer.htm 替换
源代码// 模板
$template = preg_replace("/\<\!\-\-\{template\s+([a-z0-9_\/]+)\}\-\-\>/ie", "readtemplate('\\1')", $template);// 处理子页面中的代码$template = preg_replace("/\<\!\-\-\{template\s+([a-z0-9_\/]+)\}\-\-\>/ie", "readtemplate('\\1')", $template);// 解析模块调用$template = preg_replace("/\<\!\-\-\{block\/(.+?)\}\-\-\>/ie", "blocktags('\\1')", $template);// 解析广告$template = preg_replace("/\<\!\-\-\{ad\/(.+?)\}\-\-\>/ie", "adtags('\\1')", $template);// 时间处理$template = preg_replace("/\<\!\-\-\{date\((.+?)\)\}\-\-\>/ie", "datetags('\\1')", $template);// 头像处理$template = preg_replace("/\<\!\-\-\{avatar\((.+?)\)\}\-\-\>/ie", "avatartags('\\1')", $template);//PHP 代码$template = preg_replace("/\<\!\-\-\{eval\s+(.+?)\s*\}\-\-\>/ies", "evaltags('\\1')", $template);