VBScript mb_convert_encoding function

A VBScript equivalent of PHP’s mb_convert_encoding


Function mb_convert_encoding(str,to_encoding,from_encoding)

    Dim bobj : set bobj = Server.CreateObject("basp21")
    mb_convert_encoding = bobj.Kconv(str,_
                          mb_convert_encoding_helper(to_encoding),_
                          mb_convert_encoding_helper(from_encoding))
End Function

Function mb_convert_encoding_helper(encoding)

    Dim tmp
    Select Case lcase(encoding)
    Case "shift_jis","sjis"
        tmp = 1
    Case "euc","euc-jp"
        tmp = 2
    Case "jis"
        tmp = 3
    Case "ucs2"
        tmp = 4
    Case "utf-8","utf8"
        tmp = 5
    Case "auto"
        tmp = 0
    End Select

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 mbstring extension