作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想用这个:
<?php
$string1 = 'V2h5IEkgY2FuJ3QgZG8gdGhpcyEhISEh';
echo base64_decode($string1);
?>
此示例的输出应始终为 18 个字符!但有时这个输出小于 18。
24(base64 字符)乘以 6(每个 base64 字符的位数)等于 144(位)除以 8(每个 ASCII 字符的位数)等于 18 个 ASCII 字符。
问题是输出以纯文本显示;有些字符甚至没有“文本表示”,数据将会丢失。下一个测试将显示有 41 个不同的 ASCII 字符,没有可见的输出。
<?php
for ($i = 0; $i <= 255; $i++) {
$string2 = chr($i);
echo $i . " = " . $string2 . "<br>";
}
?>
我的计划是解码 base64 字符串并从 ASCII 格式的输出中将其重新转换为十六进制。由于这 41 个字符,现在这是不可能的。
我也试过 base_convert
但没有 base64 支持。
最佳答案
您可以使用 bin2hex()
执行此操作:
Returns an ASCII string containing the hexadecimal representation of str. The conversion is done byte-wise with the high-nibble first.
php > $string1 = 'V2h5IEkgY2FuJ3QgZG8gdGhpcyEhISEh';
php > echo base64_decode($string1);
Why I can't do this!!!!!
php > echo bin2hex(base64_decode($string1));
57687920492063616e277420646f20746869732121212121
php >
关于php - 如何在 php 中将 base64 转换为十六进制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37648273/
我是一名优秀的程序员,十分优秀!