Content

one.asp多项目、函数库、类库 统一为一个版本的方法(如何使用多个项目工具创建窗体文件的快捷键)不看后悔

文章摘要

这篇文章介绍了名为**OneAsp**的类库,用于在PHP中实现多项目函数库、类库的统一管理。该类库支持文件操作(如读取、写入、包含)、HTML解析功能,以及在服务器端和客户端之间进行代码转换。核心功能包括通过`FBX`和`FSO`实现文件路径解析与转换,支持跨平台使用,并提供对HTML文件的动态包含与替换功能。文章通过代码示例展示了类库的具体实现细节,包括文件操作、HTML解析和代码转换的逻辑。

 ‘====================================================’ 类名:One ‘ 作者:mqycn ‘ 博客:http://www.miaoqiyuan.cn ‘ 源码:http://www.miaoqiyuan.cn/p/one-php ‘ 说明:多项目 函数库、类库 统一为一个版本的方法 ‘====================================================Class OneAsp Private FSO Private Root Private Sub Class_Initialize() Set FSO=Server.CreateObject(“Scripting.FileSystemObject”) End Sub Private Sub Class_Terminate() Set FSO=Nothing End Sub Public Function Run(ByVal sourceFile, ByVal saveFile) Run=”<hr><b>Input:</b>” & sourceFile & “<br><b>Result:</b>” & Save(saveFile, Include(sourceFile)) End Function Public Function Include(ByVal path) Dim tmpPath, tmpItem, arrPath, index tmpPath=”” arrPath=Split(path, “/”) For index=0 To UBound(arrPath) – 1 tmpItem=arrPath(index) tmpPath=tmpPath & tmpItem & “/” Next Include=Parse(tmpPath, arrPath(UBound(arrPath))) End Function Private Function Parse(ByVal root, ByVal fileName) Call SetRoot(root) Dim html html=OpenRead(fileName) Dim preg, pregResult Set preg=New Regexp preg.pattern=”<!–#include file=””([^””]*)””–>” preg.global=True preg.ignorecase=True Dim htmlInclude Set pregResult=preg.execute(html) For Each htmlInclude In pregResult html=Replace(html, htmlInclude, Include(root & htmlInclude.submatches(0))) Next Parse=”<% ‘” & root & fileName & ” Start %” & “>” & vbCrLf & html & vbCrLf & “<% ‘” & root & fileName & ” End %” & “>” & vbCrLf End Function Private Function SetRoot(ByVal rootPath) If Right(rootPath, 1) <> “/” Then rootPath=rootPath & “/” Root=rootPath End Function Private Function RealPath(ByVal path) RealPath=Server.Mappath(Root & path) End Function Private Function OpenRead(ByVal path) Dim txtFile Set txtFile=FSO.OpenTextFile(RealPath(path)) OpenRead=txtFile.ReadAll() txtFile.close On Error GoTo 0 End Function Public Function Save(ByVal path, ByVal body) Dim txtFile Set txtFile=FSO.CreateTextFile(Server.Mappath(path)) txtFile.write body txtFile.close Set txtFile=Nothing Save=path End Function End Class