'解析if
Public Function parseIf()
if not isExistStr(content,"{if:") then Exit Function
dim matchIf,matchesIf,strIf,strThen,strThen1,strElse1,labelRule2,labelRule3
dim ifFlag,elseIfArray,elseIfSubArray,elseIfArrayLen,resultStr,elseIfLen,strElseIf,strElseIfThen,elseIfFlag
labelRule="{if:([\s\S]+?)}([\s\S]*?){end\s+if}":labelRule2="{elseif":labelRule3="{else}":elseIfFlag=false
regExpObj.Pattern=labelRule
set matchesIf=regExpObj.Execute(content)
for each matchIf in matchesIf
strIf=matchIf.SubMatches(0):strThen=matchIf.SubMatches(1)
'echo "<h1>"&strIf &"</h1>"
if instr(strThen,labelRule2)>0 then
elseIfArray=split(strThen,labelRule2):elseIfArrayLen=ubound(elseIfArray):elseIfSubArray=split(elseIfArray(elseIfArrayLen),labelRule3)
resultStr=elseIfSubArray(1)
Execute("if "&strIf&" then resultStr=elseIfArray(0)")
for elseIfLen=1 to elseIfArrayLen-1
strElseIf=getSubStrByFromAndEnd(elseIfArray(elseIfLen),":","}","")
strElseIfThen=getSubStrByFromAndEnd(elseIfArray(elseIfLen),"}","","start")
Execute("if "&strElseIf&" then resultStr=strElseIfThen")
Execute("if "&strElseIf&" then elseIfFlag=true else elseIfFlag=false")
if elseIfFlag then exit for
next
Execute("if "&getSubStrByFromAndEnd(elseIfSubArray(0),":","}","")&" then resultStr=getSubStrByFromAndEnd(elseIfSubArray(0),""}"","""",""start""):elseIfFlag=true")
content=replace(content,matchIf.value,resultStr)
else
if instr(strThen,"{else}")>0 then
strThen1=split(strThen,labelRule3)(0)
strElse1=split(strThen,labelRule3)(1)
Execute("if "&strIf&" then ifFlag=true else ifFlag=false")
if ifFlag then content=replace(content,matchIf.value,strThen1) else content=replace(content,matchIf.value,strElse1)
else
Execute("if "&strIf&" then ifFlag=true else ifFlag=false")
if ifFlag then content=replace(content,matchIf.value,strThen) else content=replace(content,matchIf.value,"")
end if
end if
elseIfFlag=false
next
set matchesIf=nothing
End Function
这是一段ASPCMS IF判断代码,有时候行,有时候不行,出现
Microsoft VBScript 编译器错误 '800a0408'
无效字符
代码中红色的代码,如果删了,回到前台刷新,在恢复,前台刷新就能用了,
高手指点,分不多。感激不尽,好人好报哈~
Public Function parseIf()
if not isExistStr(content,"{if:") then Exit Function
dim matchIf,matchesIf,strIf,strThen,strThen1,strElse1,labelRule2,labelRule3
dim ifFlag,elseIfArray,elseIfSubArray,elseIfArrayLen,resultStr,elseIfLen,strElseIf,strElseIfThen,elseIfFlag
labelRule="{if:([\s\S]+?)}([\s\S]*?){end\s+if}":labelRule2="{elseif":labelRule3="{else}":elseIfFlag=false
regExpObj.Pattern=labelRule
set matchesIf=regExpObj.Execute(content)
for each matchIf in matchesIf
strIf=matchIf.SubMatches(0):strThen=matchIf.SubMatches(1)
'echo "<h1>"&strIf &"</h1>"
if instr(strThen,labelRule2)>0 then
elseIfArray=split(strThen,labelRule2):elseIfArrayLen=ubound(elseIfArray):elseIfSubArray=split(elseIfArray(elseIfArrayLen),labelRule3)
resultStr=elseIfSubArray(1)
Execute("if "&strIf&" then resultStr=elseIfArray(0)")
for elseIfLen=1 to elseIfArrayLen-1
strElseIf=getSubStrByFromAndEnd(elseIfArray(elseIfLen),":","}","")
strElseIfThen=getSubStrByFromAndEnd(elseIfArray(elseIfLen),"}","","start")
Execute("if "&strElseIf&" then resultStr=strElseIfThen")
Execute("if "&strElseIf&" then elseIfFlag=true else elseIfFlag=false")
if elseIfFlag then exit for
next
Execute("if "&getSubStrByFromAndEnd(elseIfSubArray(0),":","}","")&" then resultStr=getSubStrByFromAndEnd(elseIfSubArray(0),""}"","""",""start""):elseIfFlag=true")
content=replace(content,matchIf.value,resultStr)
else
if instr(strThen,"{else}")>0 then
strThen1=split(strThen,labelRule3)(0)
strElse1=split(strThen,labelRule3)(1)
Execute("if "&strIf&" then ifFlag=true else ifFlag=false")
if ifFlag then content=replace(content,matchIf.value,strThen1) else content=replace(content,matchIf.value,strElse1)
else
Execute("if "&strIf&" then ifFlag=true else ifFlag=false")
if ifFlag then content=replace(content,matchIf.value,strThen) else content=replace(content,matchIf.value,"")
end if
end if
elseIfFlag=false
next
set matchesIf=nothing
End Function
这是一段ASPCMS IF判断代码,有时候行,有时候不行,出现
Microsoft VBScript 编译器错误 '800a0408'
无效字符
代码中红色的代码,如果删了,回到前台刷新,在恢复,前台刷新就能用了,
高手指点,分不多。感激不尽,好人好报哈~