[英]Decoding base64 strings in PHP
I am trying to decode base64 string in PHP. 我正在尝试在PHP中解码base64字符串。
For example, I can do this in a python script by doing: 例如,我可以在python脚本中执行以下操作:
s = "0CC0QFjAA"
base64.b64decode(str(s)+'=====', '_-');
How can I decode base64 strings in PHP? 如何在PHP中解码base64字符串?
I think this would do it: 我认为这可以做到:
$decoded = base64_decode(str_replace(array('_', '-'), array('+', '/'), $s));
If you need the more general form: 如果您需要更一般的形式:
function b64decode($str, $altchars = null) {
if ($altchars) {
$altarray = array($altchars[0], $altchars[1]);
$str = str_replace($altarray, array('+', '/'), $str);
}
return base64_decode($str);
}
The PHP function is called base64_decode
. PHP函数称为
base64_decode
。 You could call it like base64_decode($s);
您可以像
base64_decode($s);
这样称呼它base64_decode($s);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.