<%
』************************************************************* 』轉發時請保留此聲明信息,這段聲明不並會影響你的速度! 』*************************************************************
』************************************************************* 』@author: 麵條 』@realname: 徐仁祿 』@email: xurenlu@sohu.com 』@QQ: 55547082 』@Homepage: http://www.ksdn.net 』@版權申明: 』 非盈利性質團體或者個人可以免費使用. 』************************************************************* 』 我敢擔保 本程序由本人獨立完成 ,沒有參考他人的任何程序(參考了本人自己的php版本的template,不過那個也是本人獨立完成的 .)同時本人聲明 本class的所有示例版權均為本人所有,任何人或者單位實體不得隨意更改 』 本template可免費用於: 』 1.個人的非商業性質應用。 』 2.公益性質團體,如紅十字會,孤兒院等等 』 』具體使用方法請看example.asp文件. 』 』adSaveCreateOverWrite
class template dim adSaveCreateOverWrite dim adSaveCreateNotExist public starttag public endtag public filename dim key_arr() dim val_arr() public content public total public contenta() public BlockContent 』 塊的內容(解析後的) public block_begin_delim public block_end_delim public block_begin_word public block_END_word public block_null sub Class_Initialize()』 類的初始化 redim key_arr(0) redim val_arr(0) redim contenta(0) adSaveCreateOverWrite=2 adSaveCreateNotExist=1
starttag="{" endtag="}" total=0 block_begin_word="BEGIN" block_end_word="END" block_begin_delim="<!--" block_end_delim="-->" block_null=" " 』 begin 和end之間用空格隔開 end sub
sub echo (a) response.write a end sub
function readfile(filepath) dim stm2 on error resume next set stm2 =server.createobject("ADODB.Stream") stm2.Charset = "gb2312" stm2.Open stm2.LoadFromFile filepath readfile = stm2.ReadText end function
function writefile(filepath,str)』 寫入文件的函數 dim stm on error resume next Set stm = server.createobject("ADODB.Stream") stm.Charset = "gb2312" stm.Open stm.WriteText str stm.SaveToFile filepath, adSaveCreateOverWrite end function
function SetFile(file)』 設置文件,讀取文件內容 filename=file content=readfile(file) end function
function inarray(val,arr)』val是否在數組arr中 dim tmp,i,rr,re,pt,tt for i =0 to ubound(arr) if arr(i)=val then inarray=i exit function end if next inarray=-1 』不在數組中. end function
function listarray(arr,str) dim tmp,i,rr,re,pt,tt str=" " & str for i=0 to ubound(arr) echo str & i & ":" & arr(i) & vbcrlf next end function
function NewKey(key,val) 』添加新的鍵值. dim tmp,i,rr,re,pt,tt,pos i=total pos=inarray(key,key_arr) if pos=-1 then 』//如果這個鍵值不存在. redim Preserve key_arr(i) redim Preserve val_arr(i) 』echo "key_arr(" & i & ")=" & key & vbcrlf key_arr(i)=key val_arr(i)=val total=total+1 else key_arr(pos)=key val_arr(pos)=val end if end function
function resetKeys()』 初始化鍵名數組 redim key_arr(0) redim val_arr(0) total=0 end function
function getTextContent(Tcontent) dim tmp,i,rr,re,pt,tt 』 得到把某一個文本段的{}內容替換後的塊. tmp=Tcontent for i=0 to total -1 tmp=replace(tmp & "",starttag & key_arr(i) & endtag, val_arr(i)& "" ) 』 替換各個鍵值. next 』 替換{***}類似的東西。 』 目前暫時先放一放把。 』』 』』 set re=new RegExp re.Global=True re.Ignorecase=True pt="{([a-zA-Z0-9_]{0,100})}" re.Pattern=pt set tt=re.Execute(tmp) for i= 0 to tt.count -1 tmp=replace(tmp & " ", tt.item(i) & "" ,"") next set re=nothing set tt=nothing 』』 』』 getTextContent=tmp end function
function getText() dim tmp,i,rr,re,pt,tt 』 得到把某一個文本段的{}內容替換後的塊. tmp=content for i=0 to total -1 tmp=replace(tmp & "",starttag & key_arr(i) & endtag & "", val_arr(i) & "" ) 』 替換各個鍵值. next 』 替換{***}類似的東西。 』 目前暫時先放一放把。 』』 』』 set re=new RegExp 』 這裡是模式匹配的應用 有正規表達式應用高手的指導一下! re.Global=True re.Ignorecase=True pt="{([a-zA-Z0-9_]{0,100})}" re.Pattern=pt set tt=re.Execute(tmp) for i= 0 to tt.count -1 tmp=replace(tmp & "", tt.item(i) & "","") next set re=nothing set tt=nothing 』』 』』 getText=tmp content=tmp end function
function getBlockContent(block)』 得到模板內容中某一個塊的內容 dim i,pos1,pos2,firststr,secondstr,tempstr firstStr="<!-- BEGIN " & Block & " -->" secondStr="<!-- END " & Block & " -->" pos1=instr(content,firststr) pos2=instr(content,secondstr) if (pos2-pos1)<=0 then else
tempstr=mid(content,pos1,pos2-pos1) tempstr=replace(tempstr,firststr,"") tempstr=replace(tempstr,secondstr,"") 』response.write replace(tmpstr,"<--","") end if 』response.end getBlockContent=tempstr 』 返回該字符串. end function
sub tofile(file)』 輸出到某個文件 dim tmp tmp=gettext() writefile file,content』 輸出到文件 end sub
function ParseBlock(block) 』 到到某一個塊的解析後的內容. dim b,tmp dim firststr,secondstr,tempstr b=GetBlockContent(block) 』得到某一個塊解析前的內容 tmp=getTextContent(b)』得到這個塊解析後的內容. BlockContent=BlockContent & tmp 』 保存起來拉 哈哈。這樣就實現了重複顯示某一個塊. firstStr="<!-- BEGIN " & Block & " -->" secondStr="<!-- END " & Block & " -->" tmp=replace(tmp,firststr,"") tmp=replace(tmp,secondstr,"") ParseBlock=tmp end function
function replaceBlock(block)』 把解析了幾次的塊的內容給替換解析了. dim con,tmp dim firststr,secondstr,tempstr con=GetBlockContent(block) 』得到這個塊解析前的內容. tmp=replace(content & "",con & "",Blockcontent & "") blockcontent="" firstStr="<!-- BEGIN " & Block & " -->" secondStr="<!-- END " & Block & " -->" tmp=replace(tmp,firststr,"") tmp=replace(tmp,secondstr,"") content=tmp end function
function replaceBlockforNUll(block)』 把解析了幾次的塊的內容給替換解析了. dim tmp,con con=GetBlockContent(block) 』得到這個塊解析前的內容. tmp=replace(content & "",con & "","") blockcontent="" content=tmp end function
function replaceBlockfor(block,deStr)』 把解析了幾次的塊的內容給替換解析了. dim tmp,con con=GetBlockContent(block) 』得到這個塊解析前的內容. tmp=replace(content & "",con & "",Dstr) blockcontent="" content=tmp end function end class
%>
|
|