<?php
/**
* -------------- [Nemo Template Engine] --------------
* PHPSo MVC System * Nemo 模板引擎
* 版本:V1.20 Build 2006-12-25 15:57
* 版权所有:Monkéy(QQ 10433182)
* PHPSo.Com
*
* PHPSoMVC及本Nemo模板引擎均为开源的免费工具,任何人均可以修改,修改后请保留原作者姓名及网站,谢谢。
* 如有任何开发的意见及建议欢迎和我联系,最新版本在官方网站MVC.PHPSo.Com予以发布。
*
* 可用常量、变量:
* _TPLPath_ 模板文件的路径
* _TPLCachePath_ 模板编译缓存文件的路径
* _TPLCacheLimit_ 模板编译缓存的有效期,单位秒,不定义此常量或者为 0 表示模板文件更新后才重新缓存
*
* 调用方法:
* include 'nemo.php';
* ......
* 程序内容数据获取
* ......
* include template(模板文件[, 模板文件的路径][, 模板编译缓存文件的路径][, 用户模板替换包][, 用户模板替换包路径]);
*/
//模板编译类
class nemo {
var $template;
var $cachefile;
var $htmlfile;
var $userpack;
var $extraparms;
//错误显示
function error($no) {
switch ($no) {
case 1: exit('template cache have no access!');break;
case 2: exit('userpack have no access!');break;
}
}
//子功能函数
function a($s, $u = true) {
$s = str_replace('\\\"', '"', $s);
$s = preg_replace('#{((\$[a-zA-Z_][a-zA-Z0-9_\->]*)(\[\'[a-zA-Z0-9_\.\"\'\[\]\$]+?\'\]))}#', '\1', $s);
if (!$u) $s = preg_replace('#echo "(.+?)";#e', "'echo \"'.\$this->b('\\1').'\";'", $s);
return "]];\n".$s."\necho [[";
}
function b($s) {
$s = str_replace("\\\"", "\"", $this->c($s));
$s = preg_replace('#(\$[a-zA-Z_][a-zA-Z0-9_\->]*\[\'[a-zA-Z0-9_\.\"\'\[\]\$]+?\'\])#', '{\1}', $s);
return $s;
}
function c($v) {
return preg_replace("/\[([a-zA-Z0-9_\.]+)\]/s", "['\\1']", $v);
}
function d($s) {
$s = str_replace('\\\"', '"', $s);
$s = str_replace('\'', '\\\'', $s);
$s = preg_replace('#(\$[a-zA-Z_][a-zA-Z0-9_\->]*(\[[a-zA-Z0-9_\.\[\]\$]+?\])*)#', '\'.\1.\'', $s);
$s = str_replace(']].\'', '].\']', $s);
$s = str_replace('.\'\'.', '.', $s);
return '\''.$s.'\';';
}
function e() {
if (!file_exists($this->userpack)) $this->error(2);
include $this->userpack;
if (is_array($data)) {
$this->template = preg_replace('/{\#(.+?)\#}/e', "\$data['\\1'];", $this->template);
}
}
//模板的编译
function compile() {
$var = '(\$[a-zA-Z_][a-zA-Z0-9_\->\.\[\]\$]*)';
$this->template = str_replace('"', '\"', $this->template);
if ($this->userpack != '') $this->e();
//模板语法
$find[] = '#<\?.*?\?>#is';
$replace[] = '';
$find[] = '#<!--\*\*.+?\*\*-->#s';
$replace[] = '';
$find[] = '#{\[(\S+?)\]}#';
$replace[] = '$_v_[\1]';
$find[] = '#\t*<(!--)?if:(.+?)-->#ie';
$replace[] = '$this->a(\'if (\2) {\')';
$find[] = '#\t*<(!--)?else-->#ie';
$replace[] = '$this->a(\'} else {\')';
$find[] = '#\t*<(!--)?elseif:(.+?)-->#ie';
$replace[] = '$this->a(\'} elseif (\\2) {\')';
$find[] = '#\t*<(!--)?switch:(.+?)-->#ie';
$replace[] = '$this->a(\'switch (\2) {default:\')';
$find[] = '#\t*<(!--)?case:(.+?)-->#ie';
$replace[] = '$this->a(\'break;case "\2":\')';
$find[] = '#\t*<(!--)?for:(\S+?)\s+(\S+?)-->#ie';
$replace[] = '$this->a(\'if(is_array(\2)) foreach (\2 as \3) {\')';
$find[] = '#\t*<(!--)?for:(\S+?)\s+(\S+?)\s+(\S+?)-->#ie';
$replace[] = '$this->a(\'if(is_array(\2)) foreach (\2 as \3 => \4) {\')';
$find[] = '#\t*<(!--)?for_option:(\S+?)\s+(\S+?)\s+(\S+?)\s+(\S+?)-->#ie';
$replace[] = '$this->a(\'if(is_array(\2)) foreach (\2 as $_k_ => \4) {echo \\\'<option value="\\\'.\4["\3"].\\\'"\\\'.((\4["\3"] == \5 || @in_array(\4["\3"], \5))?\\\' selected class="tpl_select"\\\':\\\'\\\').\\\'>\\\';\')';
$find[] = '#\t*<(!--)?for_checkbox\s+(\S+?):(\S+?)\s+(\S+?)\s+(\S+?)\s+(\S+?)-->#ie';
$replace[] = '$this->a(\'if(is_array(\3)) foreach (\3 as $_k_ => \5) {echo \\\'<input type="checkbox" name="\2" value="\\\'.\5["\4"].\\\'"\\\'.((\5["\4"] == \6 || @in_array(\5["\4"], \6))?\\\' checked class="tpl_checkbox"\\\':\\\'\\\').\\\'>\\\';\')';
$find[] = '#\t*<(!--)?for_radio\s+(\S+?):(\S+?)\s+(\S+?)\s+(\S+?)\s+(\S+?)-->#ie';
$replace[] = '$this->a(\'if(is_array(\3)) foreach (\3 as $_k_ => \5) {echo \\\'<input type="radio" name="\2" value="\\\'.\5["\4"].\\\'"\"\\\'.((\5["\4"] == \6)?\\\' checked class="tpl_radio"\\\':\\\'\\\').\\\'>\\\';\')';
$find[] = '#\t*<(!--)?loop:(\S+?)-->#ie';
$replace[] = '$this->a(\'if(is_array(\2)) foreach (\2 as $_v_) {\')';
$find[] = '#\t*<(!--)?loop:(\S+?)\s+(\S+?)\s+(\S+?)-->#ie';
$replace[] = '$this->a(\'for(\2;\3;\4) {\')';
$find[] = '#\t*<(!--)?include:(\S+?)-->#ie';
$replace[] = '$this->a(\'include_once template("\2"'.$this->extraparms.');\')';
$find[] = '#\t*<(!--)?func\s+(\S+?):(.*?)-->#ie';
$replace[] = '$this->a(\'function \\2(\\3) {\')';
$find[] = '#\t*<(!--)?func:(\S+?)\((.*?)\)-->#ie';
$replace[] = '$this->a(\'\\2(\\3);\')';
$find[] = '#\t*<(!--)?php:(.+?)-->#ies';
$replace[] = '$this->a(\'\2;\', false)';
$find[] = '#{echo:(.+?)}#ie';
$replace[] = '$this->a(\'echo \1;\', false)';
$find[] = '#{'.$var.':date\s+(.+?)}#ie';
$replace[] = '$this->a(\'echo date("\2", \1);\')';
$find[] = '#{'.$var.':default\s+(.+?)}#ie';
$replace[] = '$this->a(\'if (!isset(\1) || empty(\1)) echo [[\2]];\')';
$find[] = '#{'.$var.':format\s+(.+?)}#ie';
$replace[] = '$this->a(\'echo sprintf("\2", \1);\')';
$find[] = '#{'.$var.':float\s+(.+?)}#ie';
$replace[] = '$this->a(\'echo sprintf("%\2f", \1);\')';
$find[] = '#{'.$var.':specialchar\s+(.+?)}#ie';
$replace[] = '$this->a(\'echo htmlspecialchars(\1, \2);\')';
$find[] = '#{'.$var.':specialchar}#ie';
$replace[] = '$this->a(\'echo htmlspecialchars(\1, ENT_QUOTES);\')';
$find[] = '#{'.$var.':(\S+?)\((.*?)\)}#ie';
$replace[] = '$this->a(\'echo \'.("\3"== \'\' ? \'\2(\1);\' : \'\2(\1,\3);\'))';
$find[] = '#\t*<(!--)?option:(\S+?)\s+(\S+?)-->#ie';
$replace[] = '$this->a(\'if(is_array(\2)) foreach (\2 as $_k_ => $_v_) echo \\\'<option value="\\\'.$_k_.\\\'"\\\'.(($_k_ == \3 || @in_array($_k_, \3))?\\\' selected class="tpl_select"\\\':\\\'\\\').\\\'>\\\'.$_v_.\\\'</option>\\\';\')';
$find[] = '#\t*<(!--)?checkbox\s+(\S+?):(\S+?)\s+(\S+?)-->#ie';
$replace[] = '$this->a(\'if(is_array(\3)) foreach (\3 as $_k_ => $_v_) echo \\\'<input type="checkbox" name="\2" value="\\\'.$_k_.\\\'"\\\'.(($_k_ == \4 || @in_array($_k_, \4))?\\\' checked class="tpl_checkbox"\\\':\\\'\\\').\\\'>\\\'.$_v_;\')';
$find[] = '#\t*<(!--)?radio\s+(\S+?):(\S+?)\s+(\S+?)-->#ie';
$replace[] = '$this->a(\'if(is_array(\3)) foreach (\3 as $_k_ => $_v_) echo \\\'<input type="radio" name="\2" value="\\\'.$_k_.\\\'"\\\'.(($_k_ == \4)?\\\' checked class="tpl_radio"\\\':\\\'\\\').\\\'>\\\'.$_v_;\')';
$obs_count = 0;
$find[] = '#\t*<(!--)?htmlcache-->#ie';
$replace[] = '$this->a(\'/*Nemo_OB_Start_\'.(++$obs_count).\'*/ob_start();\')';
$obe_count = 0;
$find[] = '#\t*<(!--)?/htmlcache-->#ie';
$replace[] = '$this->a(\'\$ob_\'.(++$obe_count).\'=ob_get_contents();ob_end_clean();echo \$ob_\'.$obe_count.\';/*Nemo_OB_End*/\')';
//更多语法请您自由添加 ^_^
//编译文件结构调整
$this->template = preg_replace($find, $replace, $this->template);
$find = array('#<(!--)?/if-->#ie', '#<(!--)?/switch-->#ie', '#<(!--)?/for-->#ie', '#<(!--)?/for_option-->#ie', '#<(!--)?/for_checkbox-->#ie', '#<(!--)?/for_radio-->#ie', '#<(!--)?/loop-->#ie', '#<(!--)?/func-->#ie');
$this->template = preg_replace($find, '$this->a(\'}\')', $this->template);
$this->template = preg_replace('#echo "\s*";#is', '', "echo [[\n".$this->template."\n]];");
$this->template = preg_replace('#\[\[(.*?)\]\];#es', '$this->d(\'\1\')', $this->template);
$this->template = "<?php\n//Nemo Cache @ ".date('Y-m-d H:i:s')."\n".$this->template."\n?>";
$this->template = str_replace('echo \'\'.', 'echo ', $this->template);
$find = array('#((\$[a-zA-Z_][a-zA-Z0-9_]*)(\[[a-zA-Z0-9_\.\[\]\$]+\])+)#e', '#echo \'\s+\';#', '#(\r|\n)+#', '#{(\'\.\$[a-zA-Z_][a-zA-Z0-9_\->]*(\[[a-zA-Z0-9_\.\[\]\$]+?\])*\.\')}#');
$replace = array('$this->c(\'\1\')', '', '\1', '\1');
$this->template = preg_replace($find, $replace, $this->te
没有合适的资源?快使用搜索试试~ 我知道了~
php实现实时天气预报
共229个文件
gif:213个
php:9个
db:4个
2星 需积分: 50 31 下载量 170 浏览量
2008-07-22
15:23:17
上传
评论 1
收藏 2.6MB RAR 举报
温馨提示
php实现实时天气预报,很好的源代码
资源推荐
资源详情
资源评论
收起资源包目录
php实现实时天气预报 (229个子文件)
QQWry.Dat 6.85MB
Thumbs.db 281KB
Thumbs.db 58KB
Thumbs.db 57KB
Thumbs.db 6KB
wenhao.gif 3KB
l83.gif 1KB
l184.gif 1KB
l169.gif 1KB
l193.gif 1KB
l69.gif 1KB
l84.gif 1KB
l183.gif 1KB
l68.gif 1KB
l93.gif 1KB
l168.gif 1KB
l99.gif 1KB
l197.gif 1KB
l95.gif 1KB
l97.gif 1KB
l87.gif 1KB
l189.gif 1KB
l88.gif 1KB
l90.gif 1KB
l96.gif 1KB
l196.gif 1KB
l188.gif 1KB
l190.gif 1KB
l199.gif 1KB
l89.gif 1KB
l175.gif 1KB
l74.gif 1KB
l174.gif 1KB
l75.gif 1KB
l52.gif 1KB
l80.gif 1KB
l50.gif 1KB
l152.gif 1KB
l160.gif 1KB
l150.gif 1KB
l180.gif 1KB
l60.gif 1KB
l185.gif 1KB
l70.gif 1KB
l170.gif 1KB
l85.gif 1KB
l1.gif 1KB
l1.gif 1KB
l64.gif 1KB
l165.gif 1KB
l65.gif 1KB
l164.gif 1KB
l78.gif 1KB
l178.gif 1KB
l71.gif 1KB
l171.gif 1KB
l77.gif 1KB
l176.gif 1KB
l79.gif 1KB
l179.gif 1KB
l76.gif 1KB
l177.gif 1KB
l35.gif 1KB
l130.gif 1KB
l32.gif 1KB
l131.gif 1KB
l162.gif 1KB
l92.gif 1KB
l181.gif 1KB
l192.gif 1KB
l182.gif 1KB
l167.gif 1KB
l109.gif 1KB
l67.gif 1KB
l133.gif 1KB
l132.gif 1KB
l81.gif 1KB
l98.gif 1KB
l30.gif 1KB
l34.gif 1KB
l33.gif 1KB
l31.gif 1KB
l198.gif 1KB
l163.gif 1KB
l62.gif 1KB
l9.gif 1KB
l135.gif 1KB
l63.gif 1KB
l82.gif 1KB
l134.gif 1KB
l35.gif 1KB
l32.gif 1KB
l30.gif 1KB
l34.gif 1KB
l33.gif 1KB
l31.gif 1KB
l9.gif 1KB
l0.gif 1KB
l0.gif 1KB
l61.gif 1KB
共 229 条
- 1
- 2
- 3
资源评论
- hoppboy2012-09-26太繁琐,其实网址链接就可以
未来感知-UWB定位
- 粉丝: 102
- 资源: 82
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 猫咪和汤58.apk
- 浏览器.apk
- 基于matlab实现是一个matlab中的power system 中搭建的一个模型
- 基于JSP毕业设计-教学管理系统(源代码+论文).zip
- 基于JSP毕业设计-家政管理系统-毕业设计.zip
- 基于Python实现淘宝商品评论采集(含逆向)源代码
- 基于matlab实现多目标进化算法NSGAⅡ&Matlab讲解.rar
- 基于matlab实现多车辆车辆路径问题,用遗传算法编程,保证可用.rar
- 基于matlab实现多层极限学习机实现手写体识别,准确率超过99%.rar
- 基于matlab实现电力系统最优潮流程序,可以应用于电力市场下的最优潮流计算 适合电力系统专业的同仁使用.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功