php base64_encode 字符串的大小 - 文件
我想知道如何知道 base64_encoded 字符串的文件大小?例如:
$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
. 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
. 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
. '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
$data = base64_decode($data);
谢谢
I'm wondering how could I know the file size of a base64_encoded string? For instance:
$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
. 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
. 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
. '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
$data = base64_decode($data);
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据粗略的经验,base64 编码会使原始数据的大小增加约 33%
And as a rough rule of thumb, base64 encoding increases the original data in size by about 33%
如果您想在不解码的情况下知道大小,我相信以下方法有效:
或者:
否则,只需按照建议对解码后的数据使用
strlen()
即可。If you want to know the size without decoding, I believe the following works:
Or:
Otherwise, just use
strlen()
on the decoded data as Marc as suggested.试试这个,它也会给你以字节、KB 和 MB 为单位的大小。
Try this one, gives you size in Bytes, KB and MB too..
使用以下代码:
Use the following code :