得到服务器端包含文件的结果
Easp.GetInclude(filePath)
filePath | String (字符串) |
要包含的文件路径,可以是相对路径、站点绝对路径(以/开头)和硬盘绝对路径(以"盘符:\"开头) |
String (字符串) | 服务器端包含文件运行的结果 |
此方法和 Easp.Include 很相似,不同的地方是 Easp.Include 方法如果包含有HTML内容时会直接输出,而此方法会将包含文件输出的所有HTML内容返回为一个字符串变量。
可以用下面的例子来说明此方法的用法。假设有如下目录结构的文件:
├─ folder_A │ ├─ folder_1 │ │ └─ file1.asp │ └─ fileA.asp ├─ folder_B │ └─ fileB.asp └─ index.asp各个文件的内容如下:
/index.asp
<!--#include file="easp/easp.asp"--> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>测试文档</title> </head> <body> <% Dim string_Test, string_get string_Test = "<em>这是首页的string_Test的输出值。</em>" string_get = Easp.GetInclude("folder_A/fileA.asp") Easp.w Replace(string_get, "string_Test", "<em>string_new</em>") %> </body> </html>
/folder_A/fileA.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <!--#include file="folder_1/file1.asp"--> <% string_Test = "这是文件fileA.asp中的string_Test。" %> <h1><%= string_Test %></h1>
/folder_A/folder_1/file1.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% Option Explicit Response.Write("在file1.asp中输出string_Test:"&string_Test) %> <!--#include virtual="/folder_B/fileB.asp"--> <h2>这是file1.asp的内容</h2>
/folder_B/fileB.asp
<div> <h3>这是fileB.asp的内容</h3> </div> <%= "在fileB.asp中输出的string_Test:" & string_Test %>运行index.asp后,如果你查看输出的源文件代码,会是下面这样:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>测试文档</title> </head> <body> 在file1.asp中输出<em>string_new</em>:<em>这是首页的<em>string_new</em>的输出值。</em> <div> <h3>这是fileB.asp的内容</h3> </div> 在fileB.asp中输出的<em>string_new</em>:<em>这是首页的<em>string_new</em>的输出值。</em> <h2>这是file1.asp的内容</h2> <h1>这是文件fileA.asp中的<em>string_new</em>。</h1> </body> </html>在上面的例子里,index.asp 文件中,用此方法把载入的文件运行的结果存入变量
string_get
,然后把变量中的所有 string_Test
字符串替换成 <em>string_new</em>
,再输出到浏览器。