How to convert base64 index to plain string in PHP?
$let = chr(bindec($let));
It returns :
I need to convert to String.
foreach($binaryArray as $binary){
$let = str_pad($binary, 6, 0, STR_PAD_RIGHT);
//$let = bindec($let);
$let = chr(bindec($let));
$base64String .= $let;
}
CodePudding user response:
Ah, looking at the Base64 table in Wikipedia it starts to make sense to me. I think it can be as simple as this:
$binaryArray = [19,16];
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 /";
$base64String = "";
foreach ($binaryArray as $index) {
$base64String .= $chars[$index];
}
echo $base64String;
This does return "TQ". See: PHP fiddle