asp 동적 include 파일,다 중 템 플 릿 구현 편리

받다 매크로 제한,이 파일 이 존재 하고 미리 컴 파일 해 야 합 니 다.(앞에서 조건 이 있 든 없 든)  이러한 요구 가 자주 있 습 니 다.서로 다른 수요 에 따라 include 의 서로 다른 파일,예 를 들 어 각 개인의 서로 다른 설정 등 이 있 기 때문에 동적 include 파일 을 요구 합 니 다.  코드 는 다음 과 같 습 니 다: 

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("youinc.asp") 

좋은 웹페이지 즐겨찾기