Function Includeconvert (oregexp, strFileName, Strblock)
Dim Incstart, Incend, match, omatches, str, code
' Extracts the file name of the include part in the same way as the ASP code, and the remainder is output
code = ""
incend = 1
Incstart = InStr (Incend,strblock, "<!--#include") + 13 ' to find a target string <!--#include exactly 13 characters, so +13
do While incstart>incend+12 ' two reference spacing is a continuous--><--#,incstart is #include起数13个字符 from the <!--, so it takes at least more than the previous Incend 13-1 conditions of the obtained >incend+12
str = Mid (strblock,incend,incstart-incend-13)
str = replace (str, "" "" "" "" "") ' replaces single double quotes with two double quotes
str = Replace (str, vbcr, "")
str = Replace (str, VBLF, "")
str = Replace (str, VbCrLf, "")
Code = code & VbCrLf & "Response.Write" "" & Str & "" "
incend=instr (Incstart,strblock, "-->") +3
oregexp.pattern= "(w+) =" "([^"]+) "" ' Match file= "filename.ext" or virtual= "Virtualname.ext", capture type and filename two substrings
Set omatches = Oregexp.execute (Mid (strblock,incstart,incend-incstart-3))
Set match = omatches (0) ' to determine that only a set of captures, to get this set of matching substrings, you can do this, omit the for every match in omatches ... Next
Code = code & Include (Mid strFileName, 1, InStrRev (strFileName, "/") & match. Submatches (1)) ' Mid (filename, 1, InStrRev (filename, "/") extracts the path when the referenced child file name has a path, and adds it to the file name of the traditional reference in the child file to find the correct open file path. Because the file path for a dynamic reference is relative to the primary file. To a second matching substring with submatches (1)
Incstart = InStr (Incend,strblock, "<!--#include") +13
Loop
str = Mid (strblock,incend)
str = replace (str, "" "" "" "" "") ' replaces single double quotes with two double quotes
str = Replace (str, vbcr, "")
str = Replace (str, VBLF, "")
str = Replace (str, VbCrLf, "")
Code = code & VbCrLf & "Response.Write" "" & Str & "" "
Includeconvert = Code
End Function
Function include (filename)
Dim Re, content, FSO, F, Aspstart, Aspend, code
Set fso=createobject ("Scripting. FileSystemObject ")
Set F=fso. OpenTextFile (Server.MapPath (filename))
Content=f.readall
F.close
Set f=nothing
Set fso=nothing
code = ""
aspend=1
aspstart=instr (aspend,content, "<%") +2
Set re=new RegExp
Do While aspstart>aspend+1
' Traditional Quotes <!--#inclde must be outside the ASP code snippet, so go ahead.
Code = code & Includeconvert (Re, filename, Mid (content,aspend,aspstart-aspend-2))
aspend=instr (aspstart,content, "%>") +2
re.pattern= "^s*=" is replaced with <% = str% > to the standard <%response.write str% >
Code = code & VbCrLf & Re.replace (Mid (content,aspstart,aspend-aspstart-2), "Response.Write") ' ASP block before adding carriage return line To avoid multiple Response.Write errors in the same row between the connecting blocks
aspstart=instr (aspend,content, "<%") +2
Loop
Code = code & Includeconvert (Re, filename, Mid (content,aspend))
Set re=nothing
include = code
End Function |