当前位置: 网学 > 编程文档 > PHP > 正文

PHP中MVC模式的模板引擎开发经验分享

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/21
m'', ''<?php foreach (\\1 as \\2 => \\3) { ?>'', $html);
$rule = $that->eTag.''(if|loop)\s*''.$that->eFlag;
$html = preg_replace(''/''.$rule.''/ism'', ''<?php } ?>'', $html);
$rule = $that->bTag.''php\s*''.$that->eFlag.''((?:(?!''.
$that->bTag.'')[\S\s]*?|(?R))*)''.$that->eTag.''php\s*''.$that->eFlag;
$html = preg_replace(''/''.$rule.''/ism'', ''<?php \\1 ?>'', $html);
return self::TAG_Execute($html);
}
static public function TAG_List($attr, $html) {
if (!empty($html)) {
if (self::TAG_HaveTag($html)) {
return self::TAG_DealTag($attr, $html, true);
} else {
return self::TAG_GetData($attr, $html, true);
}
} else {
exit(''标签{list}的内容为空!'');
}
}
static public function TAG_Data($attr, $html) {
if (!empty($html)) {
if (self::TAG_HaveTag($html)) {
return self::TAG_DealTag($attr, $html, false);
} else {
return self::TAG_GetData($attr, $html, false);
}
} else {
exit(''标签{data}的内容为空!'');
}
}
static public function TAG_Execute($html) {
ob_clean(); ob_start();
if (!empty(self::$vars)) {
is_array(self::$vars) &&
extract(self::$vars, EXTR_OVERWRITE);
}
$file_inc = WEBSITE_DIRINC.''/buffer/''.
md5(uniqid(rand(), true)).''.php'';
if ($fp = fopen($file_inc, ''xb'')) {
fwrite($fp, $html);
if (fclose($fp)) {
include($file_inc);
$html = ob_get_contents();
} unset($fp);
} else {
exit(''模板解析文件生成失败!'');
} ob_end_clean(); @unlink($file_inc);
return $html;
}
static private function TAG_HaveTag($html) {
$bool_has = false;
$tpl_ins = new Template();
self::$rule = $tpl_ins->bTag.''([^''.$tpl_ins->eFlag.'']+)\/''.$tpl_ins->eFlag;
$bool_has = $bool_has || preg_match(''/''.self::$rule.''/ism'', $html);
self::$rule = $tpl_ins->bTag.''(\w+)\s*([^''.$tpl_ins->eFlag.'']*?)''.$tpl_ins->eFlag.
''((?:(?!''.$tpl_ins->bTag.'')[\S\s]*?|(?R))*)''.$tpl_ins->eTag.''\\1\s*''.$tpl_ins->eFlag;
$bool_has = $bool_has || preg_match(''/''.self::$rule.''/ism'', $html);
unset($tpl_ins);
return $bool_has;
}
static private function TAG_DealTag($attr, $html, $list) {
preg_match_all(''/''.self::$rule.''/ism'', $html, $out_matches);
if (!empty($out_matches[0])) {
$child_node = array();
for ($i = 0; $i < count($out_matches[0]); $i ++) {
$child_node[] = $out_matches[$i];
$html = str_ireplace($out_matches[$i], ''{-->>child_node_''.$i.''<<--}'', $html);
}
$html = self::TAG_GetData($attr, $html, $list);
for ($i = 0; $i < count($out_matches[0]); $i ++) {
$html = str_ireplace(''{-->>child_node_''.$i.''<<--}'', $child_node[$i], $html);
}
preg_match_all(''/''.self::$rule.''/ism'', $html, $tmp_matches);
if (!empty($tmp_matches[0])) {
for ($i = 0; $i < count($tmp_matches[0]); $i ++) {
$callFunc = self::$prefix.ucfirst($tmp_matches[$i]);
if (method_exists(''Tags'', $callFunc)) {
$temp = self::$callFunc($tmp_matches[$i], $tmp_matches[$i]);
$html = str_ireplace($tmp_matches[0][$i], $temp, $html);
}
}
}
unset($tmp_matches);
}
unset($out_matches); return $html;
}
static private function TAG_G

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号