当前位置:asp编程网>技术教程>Asp教程>  正文

asp实现静态页面上加自定义的if语句

2009-02-07 09:35:00   来源:asp编程网    作者:佚名   浏览量:2374   收藏
php中有一个叫smarty,可以实现在静态页面上加一些自定义的if语句,运行后实现自己想要的效果,现在我想将这种思想用asp来实现,经过一天的测试,终于搞定,现在放到这里与大家共享。
静态页面:1.html 
  <TABLE border="1" width="500">
  <TR bgcolor="<!-- if 1>22 then -->#ff0000<!-- else -->#cccccc<!-- end if -->">
 <TD>aspprogram.cn</TD>
 <TD>aaaaaaa</TD>
  </TR>
  <TR bgcolor="<!-- if 2>1 then -->#ff0000<!-- end if -->">
 <TD>bbbbbbb</TD>
 <TD>cccccc</TD>
  </TR>
  </TABLE>
要得到的效果是:
  <TABLE border="1" width="500">
  <TR bgcolor="#cccccc">
 <TD>aspprogram.cn</TD>
 <TD>aaaaaaa</TD>
  </TR>
  <TR bgcolor="#ff0000">
 <TD>bbbbbbb</TD>
 <TD>cccccc</TD>
  </TR>
  </TABLE>

实现的代码是:1.asp

< %
’===========================================
’ 代码功能:asp实现静态页面上加自定义的if语句
’ 作    者:wangsdong
’ 网    站: http://www.aspprogram.cn  
’ 文章为作者原创,转载请注明文章出处、保留作者
’ 信息,谢谢支持!
’===========================================
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
path=server.mappath("1.html")
Set MyTextFile=MyFileObject.OpenTextFile(path)
str=MyTextFile.readall
MyTextFile.Close
Set MyFileObject=Nothing
s="<!-- if .* end if -->"
response.write RegExpTest(str,s)
Function regExReplace(sSource,patrn, replStr) 
Dim regEx, str1 
str1 = sSource 
Set regEx = New RegExp 
regEx.Pattern = patrn 
regEx.IgnoreCase = True 
regEx.Global = True 
regExReplace = regEx.Replace(str1, replStr) 
End Function
Function RegExpTest(strng,s)
strng1=strng
Dim regEx, Match, Matches   ’ 建立变量。
Set regEx = New RegExp   ’ 建立正则表达式。
regEx.Pattern = s   ’ 设置模式。
regEx.IgnoreCase = True   ’ 设置是否区分大小写。
regEx.Global = True   ’ 设置全局替换。
Set Matches = regEx.Execute(strng)   ’ 执行搜索。
For Each Match in Matches   ’ 遍历 Matches 集合。
 str0=match.value
 str0=Right(str0,Len(str0)-4)
 str0=Left(str0,Len(str0)-4) 
 str2=Replace(str0,"<!--","""")
 str2=Replace(str2,"-->","kkk=""")
 str2=Replace(str2,"end if","")
 execute(str2)
 response.write vbnewline
    strng1=regExReplace(strng1,Match.value,kkk)
Next
RegExpTest = strng1
end Function
% >

关于我们-广告合作-联系我们-积分规则-网站地图

Copyright(C)2013-2017版权所属asp编程网