Google Answers Logo
View Question
 
Q: Converting ISO-2022-JP to Unicode in PHP ( No Answer,   3 Comments )
Question  
Subject: Converting ISO-2022-JP to Unicode in PHP
Category: Computers > Programming
Asked by: alexander-ga
List Price: $18.00
Posted: 15 Jul 2003 04:41 PDT
Expires: 15 Jul 2003 16:25 PDT
Question ID: 231193
Given this:

=?iso-2022-jp?B?GyRCPi5AbhsoQg==?=

(note that that's exactly what I have, there's no < ASCII 32 chars in there)

In PHP, how do I convert it (and other such ISO-2022-JP strings) to
something more useful? (i.e. UTF-8 or, preferably, Unicode character
entities)

I have iconv installed, and if it's the right command to use, I must
be doing something wrong, because I can only get it to spit out
exactly what I put in.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Converting ISO-2022-JP to Unicode in PHP
From: maitrella-ga on 15 Jul 2003 10:34 PDT
 
just my two cents...

http://si.php.net/manual/en/ref.mbstring.php
http://si.php.net:8888/manual/en/function.mb-convert-encoding.php

/* Convert ISO-2022-JP to UTF-8 */
$str = mb_convert_encoding($str, "UTF-8", "ISO-2022-JP");

Good luck !
Subject: Re: Converting ISO-2022-JP to Unicode in PHP
From: vladimir-ga on 15 Jul 2003 15:22 PDT
 
alexander,

You can convert a string from ISO-2022-JP to Unicode using the iconv()
function, like so:

$output_sting = iconv("ISO-2022-JP", "UTF-8", $input_string);

But your string looks like it's also encoded with base64. You can
decode it using the base64_decode() function. (I think it takes a
string without the leading "=?iso-2022-jp?B?" as a parameter, just
"GyRCPi5AbhsoQg==?=" in this case, you'd have to test it.)

Here is the documentation for those two functions:

http://www.php.net/manual/en/function.iconv.php

http://www.php.net/manual/en/function.base64-decode.php
Subject: Re: Converting ISO-2022-JP to Unicode in PHP
From: alexander-ga on 15 Jul 2003 16:23 PDT
 
Spot-on, vladimir. Thank you.

If I have my Base64 knowledge right, the actual encoded data is
"GyRCPi5AbhsoQg==" (4-byte chunks with = as a pad), but base64_decode
seems to just ignore any extra junk, so it also works just as you've
written it.

Good luck in becoming a researcher, if that's your goal. You've got my
vote. :)

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy