日期:2014-05-17  浏览次数:20776 次

根据需要动态include不同的文件
下面是一段网上流传广泛的动态使用include的方法。我在该方法外调用a.asp文件。
a.asp文件中内容是:定义了一个变量 <%   Name   =   "Twins "%> 请问如何才能读出变量Name的值

<%
Function   include(filename)  
Dim   re,content,fso,f,aspStart,aspEnd  

set   fso=CreateObject( "Scripting.FileSystemObject ")  
set   f=fso.OpenTextFile(server.mappath(filename))  
content=f.ReadAll  
f.close  
set   f=nothing  
set   fso=nothing  

set   re=new   RegExp  
re.pattern= "^\s*= "  
aspEnd=1  
aspStart=inStr(aspEnd,content, " <% ")+2  
do   while   aspStart> aspEnd+1  
Response.write   Mid(content,aspEnd,aspStart-aspEnd-2)  
aspEnd=inStr(aspStart,content, "%\> ")+2  
Execute(re.replace(Mid(content,aspStart,aspEnd-aspStart-2), "Response.Write   "))  
aspStart=inStr(aspEnd,content, " <% ")+2  
loop  
Response.write   Mid(content,aspEnd)  
set   re=nothing  
End   Function

include( "a.asp ")
response.write(Name)   //无法读出?????
%>


------解决方案--------------------
动态包含的话可以用Server.Execute()