Re: [PHP] [ask] convert unknown format Japanese string to readable string

[email protected] (Morning Star)
Newsgroups php.general
Message-ID <CAD9kJ0MMkdm2_xothCOCa8nRoLu9b14iPaig1kkrBckULeZtEA@mail.gmail.com>
It works!
Thanks, Koyama! :)

On Thu, Apr 11, 2013 at 8:54 AM, KOYAMA Tetsuji <[email protected]> wrote:
> Hi,
>
> On Thu, Apr 11, 2013 at 5:39 PM, Morning Star
> <[email protected]> wrote:
>> Hi guys,
>>
>> i have a string like this:
>> $string = \u3053\u3093\u306b\u3061\u306f\u30ef\u30fc\u30c9
>> (Japanese words that say "hello world" in English)
>> How can I convert that $string to Japanese character?
>> It should be 
>
> I found tips in the stackoverflow.
>
> http://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-cha
>
> I try it.
>
> <?php
> $str = "\u3053\u3093\u306b\u3061\u306f\u30ef\u30fc\u30c9";
>
> function replace_unicode_escape_sequence($match) {
>     return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
> }
> $str = preg_replace_callback('/\\\\u([0-9a-f]{4})/i',
>                              'replace_unicode_escape_sequence', $str);
> var_dump($str);
>
>
> Then it displays:
> string(24) ""
>
> regards,
>
> --
>     KOYAMA Tetsuji
>     [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.