convert byte array to unicode?

convert byte array to unicode?

am 06.11.2007 00:22:00 von realgeek

Hi. I receive a byte array that contains utf-16 string (with a lot of
\0 characters :)) from a legacy system that holds some data that is
changed elsewhere. How do I convert it to an actual utf-16 string for
my app's purposes? I am using php 5.

Re: convert byte array to unicode?

am 06.11.2007 00:37:33 von yawnmoth

On Nov 5, 5:22 pm, Sergei Shelukhin wrote:
> Hi. I receive a byte array that contains utf-16 string (with a lot of
> \0 characters :)) from a legacy system that holds some data that is
> changed elsewhere. How do I convert it to an actual utf-16 string for
> my app's purposes? I am using php 5.

After outputting the byte order mark (either chr(0xFE).chr(0xFF) or
chr(0xFF).chr(0xFE)) you'd just output the string as usual. If you're
going to output this to HTML, you'd need to specify the charset. eg.

header('Content-Type: text/html; charset=UTF-16');

Re: convert byte array to unicode?

am 06.11.2007 23:26:55 von realgeek

On Nov 6, 2:37 am, yawnmoth wrote:
> On Nov 5, 5:22 pm, Sergei Shelukhin wrote:
>
> > Hi. I receive a byte array that contains utf-16 string (with a lot of
> > \0 characters :)) from a legacy system that holds some data that is
> > changed elsewhere. How do I convert it to an actual utf-16 string for
> > my app's purposes? I am using php 5.
>
> After outputting the byte order mark (either chr(0xFE).chr(0xFF) or
> chr(0xFF).chr(0xFE)) you'd just output the string as usual. If you're
> going to output this to HTML, you'd need to specify the charset. eg.
>
> header('Content-Type: text/html; charset=UTF-16');

What about passing it to linux command line application (script
really)?

Re: convert byte array to unicode?

am 07.11.2007 15:11:01 von AnrDaemon

Greetings, Sergei Shelukhin.
In reply to Your message dated Wednesday, November 7, 2007, 01:26:55,

>> > Hi. I receive a byte array that contains utf-16 string (with a lot of
>> > \0 characters :)) from a legacy system that holds some data that is
>> > changed elsewhere. How do I convert it to an actual utf-16 string for
>> > my app's purposes? I am using php 5.
>>
>> After outputting the byte order mark (either chr(0xFE).chr(0xFF) or
>> chr(0xFF).chr(0xFE)) you'd just output the string as usual. If you're
>> going to output this to HTML, you'd need to specify the charset. eg.
>>
>> header('Content-Type: text/html; charset=UTF-16');

> What about passing it to linux command line application (script
> really)?

Passing what? UTF-16 string? Guess it's tricky if not impossible.
Try converting it to UTF-8 (using iconv i.e.)


--
Sincerely Yours, AnrDaemon