PHP to basic4android

superpet

New Member
Licensed User
Longtime User
I am PHP programmer, I spent time to search on forum and manual but no luck to convert this code below into form of b4a
Anyone can help me?

$mb_hex = '';
for($i = 0 ; $i<mb_strlen($data,'UTF-8') ; $i++)
{
$c = mb_substr($data,$i,1,'UTF-8');
$o = unpack('N',mb_convert_encoding($c,'UCS-4BE','UTF-8'));
$mb_hex .= sprintf('%04X',$o[1]);
}

Thank alot
 

agraham

Expert
Licensed User
Longtime User
It looks like you want to convert UTF-8 to UCS-4BE which I think is the same as UTF-32BE. You haven't answered the question of whether you want a Hex representation of that or not but it looks like you do.

Strings in Basic4android are always UTF-16 and are usually transformed to and from ITF-8 as they are read and written to a file. So inside Basic4android you will need to hold the characters as byte arrays if you want to handle UTF-8 and UTF-32 formats explicitly.

My ByteConverter library can convert UTF-16 strings to and from byte arrays representing any supported encoding, one of which is UTF32-BE, and the TextReader can convert Streams to and from UTF-16. The exact code you need will depend upon the source and destination of your encoded data.
 
Upvote 0

superpet

New Member
Licensed User
Longtime User
It looks like you want to convert UTF-8 to UCS-4BE which I think is the same as UTF-32BE. You haven't answered the question of whether you want a Hex representation of that or not but it looks like you do.

Strings in Basic4android are always UTF-16 and are usually transformed to and from ITF-8 as they are read and written to a file. So inside Basic4android you will need to hold the characters as byte arrays if you want to handle UTF-8 and UTF-32 formats explicitly.

My ByteConverter library can convert UTF-16 strings to and from byte arrays representing any supported encoding, one of which is UTF32-BE, and the TextReader can convert Streams to and from UTF-16. The exact code you need will depend upon the source and destination of your encoded data.

Thank you for your hint. I will try.
 
Upvote 0
Top