ASP 中文编程 新鲜吧
[code]ASP 中文编程 新鲜吧Execute.asp
--------------------------------------------
<%
TishPath=Server.MapPath(Request.ServerVariables("SCRIPT_NAME"))
TishBody=LoadFile(TishPath)
TishBody=CkZS(TishBody)
ExeStr=CuteAll(TishBody)
execute(ExeStr)
Response.end
'=================================以下备用函数============================================
'====读数据--------------------
Function LoadFile(File)
Dim objStream
On Error Resume Next
Set objStream = Server.CreateObject("ADODB.Stream")
If Err.Number=-2147221005 Then
Response.Write " 非常遗憾,您的主机不支持ADODB.Stream,不能使用本程序"
Err.Clear
Response.End
End If
With objStream
.Type = 2
.Mode = 3
.Open
.LoadFromFile File
If Err.Number<>0 Then
Response.Write " 文件"&File&"无法被打开,请检查是否存在!"
Err.Clear
Response.End
End If
.Charset = "GB2312"
.Position = 2
LoadFile = .ReadText
.Close
End With
Set objStream = Nothing
End Function
'----过虑页面内容-------------------
Function CkZS(ReStr)
dim re
ReStr=Replace(ReStr,"<!--"&"#include file=""Execute.asp""-->"&vbCrLf,"")
ReStr=Replace(ReStr,"<!--"&"#include file=""Execute.asp""-->","")
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
re.Pattern="(<!--\[%)([^W]+?)(%\]-->)"
ReStr=re.Replace(ReStr,"[%$2%]")
re.Pattern="(\<%)([^W]+?)(%\>)"
ReStr=re.Replace(ReStr,"[%$2%]")
set re=Nothing
CkZS=ReStr
End Function
'分析区分代码片===========================
Function CuteAll(ReStr)
F_ExeStr=""
dim itd,etd
itd=1
etd=1
while itd<len(ReStr)
str=""
Rstr=""
Lstr=""
Rstr=mid(ReStr,itd)
itd=InStr(itd,ReStr,"[%")
if (itd+2)<len(ReStr) and itd>0 then
etd=InStr(itd+2,ReStr,"%]")
end if
if etd>itd and itd>0 then
str=mid(ReStr,itd,(etd+2)-(itd))
itd=etd+2
else
itd=len(ReStr)
str=""
end if
Lstr=Rstr
If str<>"" and Rstr<>"" then
rlf=InStr(Rstr,str)
rlf=rlf
if rlf>0 then Lstr=left(Rstr,rlf-1)
End if
if Trim(Lstr)<>"" then
F_ExeStr=F_ExeStr&CuteOut(Lstr)
end if
if str<>"" then
F_ExeStr=F_ExeStr&ExeAll(str)
end if
wend
CuteAll=F_ExeStr
End Function
'--------执行输出Html代码---------------------------
Function CuteOut(ReStr)
K_ExeStr=""
If Not(IsNull(ReStr)) Then
word = split(ReStr, vbCrLf)
For abc = 0 to UBound(word)
word(abc)=Replace(word(abc),"""","""""")
if abc=UBound(word) then
K_ExeStr=K_ExeStr&"Response.Write("""&word(abc)&""")"&vbCrLf
else
K_ExeStr=K_ExeStr&"Response.Write("""&word(abc)&"""&vbCrLf)"&vbCrLf
end if
Next
End If
CuteOut=K_ExeStr
End Function
'--------执行中文代码镜象到ASP代码 可根据需要自由扩张---------------------------
Function ExeAll(ReStr)
E_ExeStr=ReStr
E_ExeStr=Replace(E_ExeStr,"[%","")
E_ExeStr=Replace(E_ExeStr,"%]","")
if left(Trim(E_ExeStr),1)="=" then
E_ExeStr="Response.Write("&mid(Trim(E_ExeStr),2)&")"&vbCrLf
ExeAll=E_ExeStr
exit Function
end if
dim re
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
E_ExeStr=Replace(E_ExeStr,"如果","If")
E_ExeStr=Replace(E_ExeStr,"就","Then")
E_ExeStr=Replace(E_ExeStr,"结束判断","End if")
E_ExeStr=Replace(E_ExeStr,"输出","Response.Write")
E_ExeStr=Replace(E_ExeStr,"(","(")
E_ExeStr=Replace(E_ExeStr,")",")")
re.Pattern="(取表单\()(.+?)(\))"
E_ExeStr=re.Replace(E_ExeStr,"Trim(Request($2))")
re.Pattern="(取Post表单\()(.+?)(\))"
E_ExeStr=re.Replace(E_ExeStr,"Trim(Request.Form($2))")
re.Pattern="(取Get表单\()(.+?)(\))"
E_ExeStr=re.Replace(E_ExeStr,"Trim(Request.QueryString($2))")
re.Pattern="(循环当)(.+?)(不成立)([^\<]+?)(结束循环)"
E_ExeStr=re.Replace(E_ExeStr,"While Not $2$4Wend")
re.Pattern="(循环当)(.+?)(成立)([^\<]+?)(结束循环)"
E_ExeStr=re.Replace(E_ExeStr,"While $2$4Wend")
re.Pattern="(.+?)(\+\+)"
E_ExeStr=re.Replace(E_ExeStr,"$1=$1+1")
re.Pattern="(.+?)(\-\-)"
E_ExeStr=re.Replace(E_ExeStr,"$1=$1-1")
ExeAll=E_ExeStr&vbCrLf
End Function
%>
------------------------------------------------------
测试页面 Test.asp
<!--#include file="Execute.asp"-->
测试页面:
<!--[%
A=3
如果 A=3 就
输出(A)
结束判断
H=取表单("dd")
如果 a>1 就 输出(H)
循环当A<5成立
输出(H)
A++
结束循环
输出("<br>")
for L=0 to 10
输出(H&L)
next
%]--><br>
asp格式输出:<%=h&a%><br>
中文编程格式输出:[%=H%]
<form name="form1" method="post" action="">
<label>
<input name="dd" type="text" id="dd">
</label>
<label>
<input type="submit" name="Submit" value="提交">
</label>
</form>
[/code]
页:
[1]