大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> ASP专区 -> ASP模板类[实现一维循环和二维循环,可以从文件、数据库、变量取摸板]

ASP模板类[实现一维循环和二维循环,可以从文件、数据库、变量取摸板]

时间: 2021-07-31 作者:daque

<%'=========================================================' file: class_template.asp' version:1.0' date: 2004-5-7' script written by r.h' description: asp template class'=========================================================' copyright (c) 2004 interflower studios. all rights reserved.' web: http://www.interflower.cn' need help? contact: ranhuan@msn.com'========================================================='========================================================='沙盘中替代的局部用{{%}}表白'沙盘中的轮回用<!-- begin % -->发端 <!-- end % -->中断 扶助一次嵌套class template private tmp private tpl_dir, tpl, tpl_blk private var_list, blk_list, blk_var_list private re, match, matchs private sub class_initialize sql = "" tpl_dir = "templates/" tpl = "" blk="" set var_list = server.createobject("scripting.dictionary") set blk_list = server.createobject("scripting.dictionary") set blk_var_list = server.createobject("scripting.dictionary") set re = new regexp end sub'博得主体沙盘 '========================'从变量掏出 public sub settpl(tplvar) tpl = tplvar end sub' 从db中掏出,本人窜改sql语句 public sub settpldb(tplname) dim sql, rs set rs = server.createobject("adodb.recordset") sql = "select content from templates where name = '"&tplname&"'" rs.open sql,conn,1,1 if rs.recordcount <> 1 then response.write("数据库缺点!<br>") response.end() end if tpl = rs("content") rs.close set rs = nothing end sub'从文献掏出 public sub settplfile(tplfile) dim fso, ofile set fso = server.createobject("scripting.filesystemobject") if fso.fileexists(server.mappath(tpl_dir & tplfile)) then set ofile = fso.opentextfile(server.mappath(tpl_dir & tplfile)) tpl = ofile.readall ofile.close set ofile = nothing else response.write "沙盘文献不生存!<br>" end if set fso = nothing end sub'博得区块沙盘 '========================'从变量掏出 public sub setblk(blkname, tplvar) re.ignorecase = true re.global = true re.pattern = {{ & blkname & }} tpl = re.replace(tpl, tplvar) rs.close end sub'从数据库掏出 public sub setblkdb(blkname, tplname) dim sql, rs set rs = server.createobject("adodb.recordset") sql = "select * from templates where name = '"&tplname&"'" rs.open sql,conn,1,1 tmp = rs("content") rs.close setblk blkname, tmp set rs = nothing end sub'从文献掏出 public sub setblkfile(blkname, tplfile) dim fso, ofile set fso = createobject("scripting.filesystemobject") if fso.fileexists(server.mappath(tpl_dir &tplfile)) then set ofile = fso.opentextfile(server.mappath(tpl_dir &tplfile)) tmp = ofile.readal setblock blkname, tmp ofile.close set ofile = nothing else response.write "区块沙盘文献不生存!<br>" end if set fso = nothing end sub'树立变量替代值 '========================'大略替代 public sub setvar(sname, svalue) if var_list.exists(sname) then var_list.remove sname var_list.add sname, svalue else var_list.add sname, svalue end if end sub'大略替代 追加数据 public sub appendvar(sname, svalue) if var_list.exists(sname) then tmp = var_list.item(sname) & svalue var_list.remove sname var_list.add sname, tmp else var_list.add sname, svalue end if end sub'轮回替代 '======================== '一维轮回发端 public sub udblk(blkname) tpl_blk = blkname re.ignorecase = true re.global = true re.pattern = "<!--\s+begin\s+(" & blkname & ")\s+-->([\s\s.]*)<!--\s+end\s+\1\s+-->" set matches = re.execute(tpl) if matches.count > 0 then set match = matches for each match in matches blk_list.add blkname, match.submatches(1) var_list.add blkname, "" tpl = re.replace(tpl, "{{"&blkname&"}}") next else response.write "block " & blkname & " does not exists!" end if end sub'一维轮回中断 public sub psblk(blkname) tmp = blk_list.item(blkname) re.ignorecase = true re.global = true re.pattern = "(" & p_var_tag_o & ")([^}]+)" & p_var_tag_c set matches = re.execute(tmp) for each match in matches if blk_var_list.exists(match.submatches(1)) then re.pattern = match.value tmp = re.replace(tmp, blk_var_list.item(match.submatches(1))) end if next tmp = var_list.item(blkname) & tmp var_list.remove blkname var_list.add blkname, tmp blk_var_list.removeall end sub'二维轮回发端 public sub udblk2(blkname) tmp = blk_list.item(tpl_blk) re.ignorecase = true re.global = true re.pattern = "<!--\s+begin\s+(" & blkname & ")\s+-->([\s\s.]*)<!--\s+end\s+\1\s+-->" set matches = re.execute(tmp) if matches.count > 0 then set match = matches for each match in matches blk_list.add blkname, match.submatches(1) 'response.write match.submatches(1) blk_var_list.add blkname, "" tmp = re.replace(tmp, "{{"&blkname&"}}") blk_list.remove tpl_blk blk_list.add tpl_blk, tmp next else response.write "block " & blkname & " does not exists!" end if end sub '二维轮回中断 public sub psblk2(blkname) tmp = blk_list.item(blkname) re.ignorecase = true re.global = true re.pattern = "(" & p_var_tag_o & ")([^}]+)" & p_var_tag_c set matches = re.execute(tmp) for each match in matches if blk_var_list.exists(match.submatches(1)) then re.pattern = match.value tmp = re.replace(tmp, blk_var_list.item(match.submatches(1))) end if next tmp = blk_var_list.item(blkname) & tmp blk_var_list.removeall blk_var_list.add blkname, tmp end sub'轮回中的替代 public sub setblkvar(s, v) if blk_var_list.exists(s) then blk_var_list.remove s blk_var_list.add s, v else blk_var_list.add s, v end if end sub'领会沙盘和输入实质 '========================'实行领会'不妨经过底下的进程博得网页实质,贯串fso不妨天生静态页面 public property gettpl re.ignorecase = true re.global = true re.pattern = "(" & {{ & ")([^}]+)" & }} set matches = re.execute(tpl) for each match in matches if var_list.exists(match.submatches(1)) then re.pattern = match.value tpl = re.replace(tpl, var_list.item(match.submatches(1))) end if next gettpl = tpl end property'输入实质 public sub parse response.write tpl end subend class%><%'=========================================================' file: class_template.asp' version:1.0' date: 2004-5-7' script written by r.h' description: asp template class'=========================================================' copyright (c) 2004 interflower studios. all rights reserved.' web: http://www.interflower.cn' need help? contact: ranhuan@msn.com'========================================================='========================================================='沙盘中替代的局部用{{%}}表白'沙盘中的轮回用<!-- begin % -->发端 <!-- end % -->中断 扶助一次嵌套class template private tmp private tpl_dir, tpl, tpl_blk private var_list, blk_list, blk_var_list private re, match, matchs private sub class_initialize sql = "" tpl_dir = "templates/" tpl = "" blk="" set var_list = server.createobject("scripting.dictionary") set blk_list = server.createobject("scripting.dictionary") set blk_var_list = server.createobject("scripting.dictionary") set re = new regexp end sub'博得主体沙盘 '========================'从变量掏出 public sub settpl(tplvar) tpl = tplvar end sub' 从db中掏出,本人窜改sql语句 public sub settpldb(tplname) dim sql, rs set rs = server.createobject("adodb.recordset") sql = "select content from templates where name = '"&tplname&"'" rs.open sql,conn,1,1 if rs.recordcount <> 1 then response.write("数据库缺点!<br>") response.end() end if tpl = rs("content") rs.close set rs = nothing end sub'从文献掏出 public sub settplfile(tplfile) dim fso, ofile set fso = server.createobject("scripting.filesystemobject") if fso.fileexists(server.mappath(tpl_dir & tplfile)) then set ofile = fso.opentextfile(server.mappath(tpl_dir & tplfile)) tpl = ofile.readall ofile.close set ofile = nothing else response.write "沙盘文献不生存!<br>" end if set fso = nothing end sub'博得区块沙盘 '========================'从变量掏出 public sub setblk(blkname, tplvar) re.ignorecase = true re.global = true re.pattern = {{ & blkname & }} tpl = re.replace(tpl, tplvar) rs.close end sub'从数据库掏出 public sub setblkdb(blkname, tplname) dim sql, rs set rs = server.createobject("adodb.recordset") sql = "select * from templates where name = '"&tplname&"'" rs.open sql,conn,1,1 tmp = rs("content") rs.close setblk blkname, tmp set rs = nothing end sub'从文献掏出 public sub setblkfile(blkname, tplfile) dim fso, ofile set fso = createobject("scripting.filesystemobject") if fso.fileexists(server.mappath(tpl_dir &tplfile)) then set ofile = fso.opentextfile(server.mappath(tpl_dir &tplfile)) tmp = ofile.readal setblock blkname, tmp ofile.close set ofile = nothing else response.write "区块沙盘文献不生存!<br>" end if set fso = nothing end sub'树立变量替代值 '========================'大略替代 public sub setvar(sname, svalue) if var_list.exists(sname) then var_list.remove sname var_list.add sname, svalue else var_list.add sname, svalue end if end sub'大略替代 追加数据 public sub appendvar(sname, svalue) if var_list.exists(sname) then tmp = var_list.item(sname) & svalue var_list.remove sname var_list.add sname, tmp else var_list.add sname, svalue end if end sub'轮回替代 '======================== '一维轮回发端 public sub udblk(blkname) tpl_blk = blkname re.ignorecase = true re.global = true re.pattern = "<!--\s+begin\s+(" & blkname & ")\s+-->([\s\s.]*)<!--\s+end\s+\1\s+-->" set matches = re.execute(tpl) if matches.count > 0 then set match = matches for each match in matches blk_list.add blkname, match.submatches(1) var_list.add blkname, "" tpl = re.replace(tpl, "{{"&blkname&"}}") next else response.write "block " & blkname & " does not exists!" end if end sub'一维轮回中断 public sub psblk(blkname) tmp = blk_list.item(blkname) re.ignorecase = true re.global = true re.pattern = "(" & p_var_tag_o & ")([^}]+)" & p_var_tag_c set matches = re.execute(tmp) for each match in matches if blk_var_list.exists(match.submatches(1)) then re.pattern = match.value tmp = re.replace(tmp, blk_var_list.item(match.submatches(1))) end if next tmp = var_list.item(blkname) & tmp var_list.remove blkname var_list.add blkname, tmp blk_var_list.removeall end sub'二维轮回发端 public sub udblk2(blkname) tmp = blk_list.item(tpl_blk) re.ignorecase = true re.global = true re.pattern = "<!--\s+begin\s+(" & blkname & ")\s+-->([\s\s.]*)<!--\s+end\s+\1\s+-->" set matches = re.execute(tmp) if matches.count > 0 then set match = matches for each match in matches blk_list.add blkname, match.submatches(1) 'response.write match.submatches(1) blk_var_list.add blkname, "" tmp = re.replace(tmp, "{{"&blkname&"}}") blk_list.remove tpl_blk blk_list.add tpl_blk, tmp next else response.write "block " & blkname & " does not exists!" end if end sub '二维轮回中断 public sub psblk2(blkname) tmp = blk_list.item(blkname) re.ignorecase = true re.global = true re.pattern = "(" & p_var_tag_o & ")([^}]+)" & p_var_tag_c set matches = re.execute(tmp) for each match in matches if blk_var_list.exists(match.submatches(1)) then re.pattern = match.value tmp = re.replace(tmp, blk_var_list.item(match.submatches(1))) end if next tmp = blk_var_list.item(blkname) & tmp blk_var_list.removeall blk_var_list.add blkname, tmp end sub'轮回中的替代 public sub setblkvar(s, v) if blk_var_list.exists(s) then blk_var_list.remove s blk_var_list.add s, v else blk_var_list.add s, v end if end sub'领会沙盘和输入实质 '========================'实行领会'不妨经过底下的进程博得网页实质,贯串fso不妨天生静态页面 public property gettpl re.ignorecase = true re.global = true re.pattern = "(" & {{ & ")([^}]+)" & }} set matches = re.execute(tpl) for each match in matches if var_list.exists(match.submatches(1)) then re.pattern = match.value tpl = re.replace(tpl, var_list.item(match.submatches(1))) end if next gettpl = tpl end property'输入实质 public sub parse response.write tpl end subend class%><%'=========================================================' file: class_template.asp' version:1.0' date: 2004-5-7' script written by r.h' description: asp template class'=========================================================' copyright (c) 2004 interflower studios. all rights reserved.' web: http://www.interflower.cn' need help? contact: ranhuan@msn.com'========================================================='========================================================='沙盘中替代的局部用{{%}}表白'沙盘中的轮回用<!-- begin % -->发端 <!-- end % -->中断 扶助一次嵌套class template private tmp private tpl_dir, tpl, tpl_blk private var_list, blk_list, blk_var_list private re, match, matchs private sub class_initialize sql = "" tpl_dir = "templates/" tpl = "" blk="" set var_list = server.createobject("scripting.dictionary") set blk_list = server.createobject("scripting.dictionary") set blk_var_list = server.createobject("scripting.dictionary") set re = new regexp end sub'博得主体沙盘 '========================'从变量掏出 public sub settpl(tplvar) tpl = tplvar end sub' 从db中掏出,本人窜改sql语句 public sub settpldb(tplname) dim sql, rs set rs = server.createobject("adodb.recordset") sql = "select content from templates where name = '"&tplname&"'" rs.open sql,conn,1,1 if rs.recordcount <> 1 then response.write("数据库缺点!<br>") response.end() end if tpl = rs("content") rs.close set rs = nothing end sub'从文献掏出 public sub settplfile(tplfile) dim fso, ofile set fso = server.createobject("scripting.filesystemobject") if fso.fileexists(server.mappath(tpl_dir & tplfile)) then set ofile = fso.opentextfile(server.mappath(tpl_dir & tplfile)) tpl = ofile.readall ofile.close set ofile = nothing else response.write "沙盘文献不生存!<br>" end if set fso = nothing end sub'博得区块沙盘 '========================'从变量掏出 public sub setblk(blkname, tplvar) re.ignorecase = true re.global = true re.pattern = {{ & blkname & }} tpl = re.replace(tpl, tplvar) rs.close end sub'从数据库掏出 public sub setblkdb(blkname, tplname) dim sql, rs set rs = server.createobject("adodb.recordset") sql = "select * from templates where name = '"&tplname&"'" rs.open sql,conn,1,1 tmp = rs("content") rs.close setblk blkname, tmp set rs = nothing end sub'从文献掏出 public sub setblkfile(blkname, tplfile) dim fso, ofile set fso = createobject("scripting.filesystemobject") if fso.fileexists(server.mappath(tpl_dir &tplfile)) then set ofile = fso.opentextfile(server.mappath(tpl_dir &tplfile)) tmp = ofile.readal setblock blkname, tmp ofile.close set ofile = nothing else response.write "区块沙盘文献不生存!<br>" end if set fso = nothing end sub'树立变量替代值 '========================'大略替代 public sub setvar(sname, svalue) if var_list.exists(sname) then var_list.remove sname var_list.add sname, svalue else var_list.add sname, svalue end if end sub'大略替代 追加数据 public sub appendvar(sname, svalue) if var_list.exists(sname) then tmp = var_list.item(sname) & svalue var_list.remove sname var_list.add sname, tmp else var_list.add sname, svalue end if end sub'轮回替代 '======================== '一维轮回发端 public sub udblk(blkname) tpl_blk = blkname re.ignorecase = true re.global = true re.pattern = "<!--\s+begin\s+(" & blkname & ")\s+-->([\s\s.]*)<!--\s+end\s+\1\s+-->" set matches = re.execute(tpl) if matches.count > 0 then set match = matches for each match in matches blk_list.add blkname, match.submatches(1) var_list.add blkname, "" tpl = re.replace(tpl, "{{"&blkname&"}}") next else response.write "block " & blkname & " does not exists!" end if end sub'一维轮回中断 public sub psblk(blkname) tmp = blk_list.item(blkname) re.ignorecase = true re.global = true re.pattern = "(" & p_var_tag_o & ")([^}]+)" & p_var_tag_c set matches = re.execute(tmp) for each match in matches if blk_var_list.exists(match.submatches(1)) then re.pattern = match.value tmp = re.replace(tmp, blk_var_list.item(match.submatches(1))) end if next tmp = var_list.item(blkname) & tmp var_list.remove blkname var_list.add blkname, tmp blk_var_list.removeall end sub'二维轮回发端 public sub udblk2(blkname) tmp = blk_list.item(tpl_blk) re.ignorecase = true re.global = true re.pattern = "<!--\s+begin\s+(" & blkname & ")\s+-->([\s\s.]*)<!--\s+end\s+\1\s+-->" set matches = re.execute(tmp) if matches.count > 0 then set match = matches for each match in matches blk_list.add blkname, match.submatches(1) 'response.write match.submatches(1) blk_var_list.add blkname, "" tmp = re.replace(tmp, "{{"&blkname&"}}") blk_list.remove tpl_blk blk_list.add tpl_blk, tmp next else response.write "block " & blkname & " does not exists!" end if end sub '二维轮回中断 public sub psblk2(blkname) tmp = blk_list.item(blkname) re.ignorecase = true re.global = true re.pattern = "(" & p_var_tag_o & ")([^}]+)" & p_var_tag_c set matches = re.execute(tmp) for each match in matches if blk_var_list.exists(match.submatches(1)) then re.pattern = match.value tmp = re.replace(tmp, blk_var_list.item(match.submatches(1))) end if next tmp = blk_var_list.item(blkname) & tmp blk_var_list.removeall blk_var_list.add blkname, tmp end sub'轮回中的替代 public sub setblkvar(s, v) if blk_var_list.exists(s) then blk_var_list.remove s blk_var_list.add s, v else blk_var_list.add s, v end if end sub'领会沙盘和输入实质 '========================'实行领会'不妨经过底下的进程博得网页实质,贯串fso不妨天生静态页面 public property gettpl re.ignorecase = true re.global = true re.pattern = "(" & {{ & ")([^}]+)" & }} set matches = re.execute(tpl) for each match in matches if var_list.exists(match.submatches(1)) then re.pattern = match.value tpl = re.replace(tpl, var_list.item(match.submatches(1))) end if next gettpl = tpl end property'输入实质 public sub parse response.write tpl end subend class%>

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.