VBScript file function

A VBScript equivalent of PHP’s file



Const FILE_IGNORE_NEW_LINES = 2
Const FILE_SKIP_EMPTY_LINES = 4

Function file(filename,flags)

    Dim req,tmp,key
    req = file_get_contents(filename)

    If flags = FILE_SKIP_EMPTY_LINES Then
        var_dump req
        tmp = preg_replace("/^" & vbCrLf & "/is",",req,",")
        tmp = Split(tmp,vbCrLf)
    Else
        tmp = Split(req,vbCrLf)

        If flags = FILE_IGNORE_NEW_LINES Then
            For key = 0 to uBound(tmp)
                tmp(key) = tmp(key) & vbCrLf
            Next
        End If
    End If

    file = tmp

End Function

Please also note that php.vbs offers community built functions and goes by the McDonald’s Theory. We’ll put online functions that are far from perfect, in the hopes to spark better contributions. Do you have one? Then please just:

Other PHP functions in the filesystem extension