解码 base64 字符串 - php
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18842075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Decode base64 string - php
提问by thuk
Is there any way to decode this string??
有没有办法解码这个字符串?
Actual string : 其他語言測試 - testing
实际字符串 : 其他语言测试 - testing
base64 encode while sending on mail as subject as
base64 编码,同时作为主题发送邮件
"=?iso-2022-jp?B?GyRCQjZCPjhsOEBCLDtuGyhCIC0gdGVzdGluZw==?="
"=?iso-2022-jp?B?GyRCQjZCPjhsOEBCLDtuGyhCIC0gdGVzdGluZw==?="
<?php
echo base64_decode('GyRCQjZCPjhsOEBCLDtuGyhCIC0gdGVzdGluZw==');
?>
This is base 64 encode, I couldn't decode it to actual Chinese string.Since it has been encoded using "iso-2022-jp", I have also tried online base64decode.org site to decode this string, but I couldn't find the original string, how can I do that?
这是base 64编码,我无法将其解码为实际的中文字符串。由于它已使用“iso-2022-jp”进行编码,因此我也尝试过在线base64decode.org站点来解码此字符串,但我无法找到原始字符串,我该怎么做?
回答by Jason OOO
回答by duskwuff -inactive-
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:
您正在查看的是 MIME 标头编码。它可以由 解码,并由mb_decode_mimeheader()
生成mb_encode_mimeheader()
。例如:
<?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.)
(mb_internal_encoding()
这里需要调用 to因为主题行的内容不能用 ISO8859-1 的默认内部编码表示。)
回答by Daniel Perez
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:
尝试先将字符串编码为 UTF-8,然后将其编码为 base 64。解码时相同,先从 base64 解码字符串,然后再从 UTF-8 解码。这对我有用:
php > $base = "其他語言測試 - testing";
php > $encoded = base64_encode(utf8_encode($base));
php > $decoded = utf8_decode(base64_decode($encoded));
php > echo ($decoded === $base) . "\n";
1