Home > Backend Development > PHP Tutorial > Can the md5 result of PHP be converted to binary and then base64 encoded to shorten the length?

Can the md5 result of PHP be converted to binary and then base64 encoded to shorten the length?

WBOY
Release: 2016-08-10 09:07:27
Original
1988 people have browsed it

The question is roughly the same as the title. Simple hexadecimal conversion seems to only get strings of 0 and 1, not binary data. I hope to know how to write this code. Can I try to use PHP’s built-in functions to achieve it

The purpose is to generate a shorter unique identifier. Previously, md5 was used to determine whether it is duplicated, but the md5 result is a 32-digit hexadecimal string, which is still a bit long, so I want to convert it to a 64-digit string. I don’t know. Are there any mistakes in my thinking?

Reply content:

The question is roughly the same as the title. Simple hexadecimal conversion seems to only get strings of 0 and 1, not binary data. I hope to know how to write this code. Can I try to use PHP’s built-in functions to achieve it

The purpose is to generate a shorter unique identifier. Previously, md5 was used to determine whether it is duplicated, but the md5 result is a 32-digit hexadecimal string, which is still a bit long, so I want to convert it to a 64-digit string. I don’t know. Are there any mistakes in my thinking?

Solved it by myself:

<code>function base64md5 ($str) {
 return base64_encode(md5($str, 1));
}</code>
Copy after login

ps: It’s roughly the same as above. The code written on the mobile phone is not guaranteed to be correct...

You can use 16-bit md5.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template