unicode,utf-8,ucs2 :(

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
newbiee
Forum Newbie
Posts: 6
Joined: Fri Aug 20, 2004 3:23 pm

unicode,utf-8,ucs2 :(

Post by newbiee »

hi all,

90b17ff06587 <- this is chinese character.


I would like to convert the above to : %C2%B1%C3%B0%C2%87

any ideas?

TIA
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

What ideas are you exactly looking for. How to convert it perhaps?
newbiee
Forum Newbie
Posts: 6
Joined: Fri Aug 20, 2004 3:23 pm

Post by newbiee »

Joe wrote:What ideas are you exactly looking for. How to convert it perhaps?
hi Joe,

would like to convert : 90b17ff06587 to : %C2%B1%C3%B0%C2%87

any ideas?

TIA
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I don't see how that string converts to the result you are looking for. The numbers don't jive.
newbiee
Forum Newbie
Posts: 6
Joined: Fri Aug 20, 2004 3:23 pm

Post by newbiee »

feyd wrote:I don't see how that string converts to the result you are looking for. The numbers don't jive.

hi feyd

Exactly, but i am receiving : %C2%B1%C3%B0%C2%87 in the HTTP headers, was wondering how to convert it ..... weird ehhh...
:(
TIA..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

have you tried, [php_man]urldecode[/php_man]()?
newbiee
Forum Newbie
Posts: 6
Joined: Fri Aug 20, 2004 3:23 pm

Post by newbiee »

feyd wrote:have you tried, [php_man]urldecode[/php_man]()?
hi feyd,

this is what i get : ±ð‡ after using the urldecode..

TIA
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that creates 2 chinese characters for me, once I switch character sets...
newbiee
Forum Newbie
Posts: 6
Joined: Fri Aug 20, 2004 3:23 pm

Post by newbiee »

feyd wrote:that creates 2 chinese characters for me, once I switch character sets...
hi feyd,
i persume this is the chinese characters you get : ±ð&#135; but if you would to convert the : 90b17ff06587 , the output is not the same. anyway thanks alot for helping out.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

newbiee wrote:
feyd wrote:that creates 2 chinese characters for me, once I switch character sets...
hi feyd,
i persume this is the chinese characters you get : ±ð&#135; but if you would to convert the : 90b17ff06587 , the output is not the same. anyway thanks alot for helping out.
簣簸 are the 2 characters..

If the byte stream you are getting is 16-bit unicode, they'll be:

邱翰文

which when run through a browser, produced 3 chinese characters.

Note: I converted the byte stream as big endian 16bit unicode.
newbiee
Forum Newbie
Posts: 6
Joined: Fri Aug 20, 2004 3:23 pm

Post by newbiee »

feyd wrote:
newbiee wrote:
feyd wrote:that creates 2 chinese characters for me, once I switch character sets...
hi feyd,
i persume this is the chinese characters you get : ±ð&#135; but if you would to convert the : 90b17ff06587 , the output is not the same. anyway thanks alot for helping out.
簣簸 are the 2 characters..

If the byte stream you are getting is 16-bit unicode, they'll be:

邱翰文

which when run through a browser, produced 3 chinese characters.

Note: I converted the byte stream as big endian 16bit unicode.

hi feyd,
thanks a lot for taking u time helping out, do you mind sharing your code.

TIA
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I didn't use code to convert them I just hand (sorta) converted them to their integer values..

if it's big endian, 16bit unicode:

Code: Select all

<?php

$stream = '90b17ff06587';

$characters = preg_split('#([0-9a-f]{4})#i',$stream,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);

foreach($characters as $k => $v)
{
  $characters[$k] = '&' . hexdec($v) . ';';
}

echo implode('',$characters);

?>
untested
Post Reply