VBScript base64_encode function

A VBScript equivalent of PHP’s base64_encode


Function base64_encode(data)

    Dim obj
    set obj=server.createobject("basp21")
    base64_encode = obj.Base64(data,0)
    set obj = nothing

    '
    'not using basp21
    '

'    Dim ST, DM, EL, bin
'  
'    Set ST = CreateObject("ADODB.Stream")
'    ST.Type = adTypeText
'    ST.Charset = "Shift-JIS"
'    ST.Open
'    ST.WriteText PlainText
'    ST.Position = 0
'    ST.Type = adTypeBinary
'    bin = ST.Read
'    ST.Close
' 
'    Set DM = CreateObject("Microsoft.XMLDOM")
'    Set EL = DM.CreateElement("tmp")
'    EL.DataType = "bin.base64"
'    EL.NodeTypedValue = bin
'    base64_encode = EL.Text
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 url extension