PDA

View Full Version : PHP Function Equivalent in ASP?


Jason_Beaudoin
06-03-2003, 04:09 PM
Does anyone know whether there is a way to get the same results in ASP that you would using the following PHP function:

$myText = utf8_encode($myText);

This PHP function encodes a string of data to UTF-8, and returns the encoded version. Is there an equivalent in ASP?

DESPERATELY seeking a solution to this problem! :(

Thanks!

Roy Sinclair
06-03-2003, 04:56 PM
The whole page will be Unicode which will make all strings in the page utf8 but:


session.CodePage=65001 'UTF-8 Codepage supported only in iis5.0 and later

Jason_Beaudoin
06-03-2003, 07:09 PM
Thanks Roy... but that isn't what I was asking for. I need the function.

But it's ok... I finally found my solution on another forum. Here it is:

Function Encode_UTF8(astr)
Dim c
Dim utftext
utftext = ""

For n = 1 To Len(astr)
c = AscW(Mid(astr, n, 1))
If c < 128 Then
utftext = utftext + Mid(astr, n, 1)
ElseIf ((c > 127) And (c < 2048)) Then
utftext = utftext + Chr(((c \ 64) Or 192))
utftext = utftext + Chr(((c And 63) Or 128))
Else
utftext = utftext + Chr(((c \ 144) Or 234))
utftext = utftext + Chr((((c \ 64) And 63) Or 128))
utftext = utftext + Chr(((c And 63) Or 128))
End If
Next
Encode_UTF8 = utftext
End Function