Decode base64 string - php

前端 未结 3 491
一向
一向 2021-01-14 18:27

Is there any way to decode this string??

Actual string : 其他語言測試 - testing

base64 encode while sending on mail as subject as

\"=?iso-2022-jp?B?GyRCQj

相关标签:
3条回答
  • 2021-01-14 19:16

    Use iconv():

    <?php
    $input = base64_decode('GyRCQjZCPjhsOEBCLDtuGyhCIC0gdGVzdGluZw==');//$BB6B>8l8@B,;n(B - testing
    $input_encoding = 'iso-2022-jp';
    echo iconv($input_encoding, 'UTF-8', $input); //其他語言測試 - testing
    ?>
    
    0 讨论(0)
  • 2021-01-14 19:21

    Try encoding the string to UTF-8 first and then encode it to base 64. Same when decoding, decode the string from base64 and then from UTF-8. This is working for me:

    php > $base = "其他語言測試 - testing";
    php > $encoded = base64_encode(utf8_encode($base));
    php > $decoded = utf8_decode(base64_decode($encoded));
    php > echo ($decoded === $base) . "\n";
    1
    
    0 讨论(0)
  • 2021-01-14 19:27

    What you are looking at is MIME header encoding. It can be decoded by mb_decode_mimeheader(), and generated by mb_encode_mimeheader(). For example:

    <?php
    mb_internal_encoding("utf-8");
    $subj = "=?iso-2022-jp?B?GyRCQjZCPjhsOEBCLDtuGyhCIC0gdGVzdGluZw==?=";
    print mb_decode_mimeheader($subj);
    ?>
    
    其他語言測試 - testing
    

    (The call to mb_internal_encoding() is necessary here because the contents of the subject line can't be represented in the default internal encoding of ISO8859-1.)

    0 讨论(0)
提交回复
热议问题