in reply to Re: how to change unicode string to byte array ?
in thread how to change unicode string to byte array ?

Thanks so much graff and others I now understand a little more about data types. may be my data is in wrong format in table. And i found that i also have some problems on communication between program and client as Burak advised me. For this encoding mismatch in communication, i used as "default-character-set=sjis" and " skip-character-set-client-handshake" in my.ini of mysql. Is this ok when i upload to some real hosting ? i convert like that and i used sjis to store data in database.Then, the query problem of "SELECT ... WHERE field1 LIKE "$input"."%"become OK since user input is also in sjis encoding. Anyway, i am really grateful for your good advises. i have some other related problem. this is to convert ascii character 'A' to sjis (japanese full-width alphanumeric character) 'A' . But I am not sure that "the solution may be only known by the people who are working in japanese character" or such problem also exists in other unicode characters.
  • Comment on Re^2: how to change unicode string to byte array ?

Replies are listed 'Best First'.
Re^3: how to change unicode string to byte array ?
by graff (Chancellor) on Sep 29, 2008 at 23:30 UTC
    i have some other related problem. this is to convert ascii character 'A' to sjis (japanese full-width alphanumeric character) 'A' .

    The easiest way might be to convert "plain ascii" characters into the unicode "fullwidth" characters first, then "Encode::encode()" the unicode string into shiftjis for output.

    The unicode range for the "fullwidth" ASCII characters begins at \x{FF01} for "!" (exclamation mark), and then proceeds through the normal ASCII character sequence up through \x{FF5E}. So one way to convert "plain ASCII" to "fullwidth ASCII" would be like this:

    use Encode; # pick one of the following lines to uncomment # (depends on what sort of display terminal you use): #binmode STDOUT, ":utf8"; #binmode STDOUT, ":encoding(shiftjis)"; $_ = join( '', map { chr() } 0x21 .. 0x7e ) . "\n"; # this is a test +string print; s/([!-~])/chr(ord($1)+0xFEE0)/eg; # convert plain ASCII to CJK fullwi +dth ASCII # print; # uncomment this when you have chosen which binmode line to +use
    (update: adding missing colon in 2nd binmode line)