Home  >  Article  >  php教程  >  md5 16位二进制与32位字符串相互转换示例

md5 16位二进制与32位字符串相互转换示例

WBOY
WBOYOriginal
2016-06-06 20:25:561387browse

密码很多时候都会用 md5保存,并且很多时候都是16位二进制格式的md5,php 里面 md5($str, true) 可以很方便的获


复制代码 代码如下:


$str = 'test';
$cm = md5($str);
$bm = md5($str, true);

$cstr = implode(unpack('H*', $bm));
$bstr = pack('H*', $cm);


echo 'str:'. $str . "
\n";
echo 'cm :' . $cm . "
\n";
echo 'cstr:' . $cstr . "
\n";
echo 'urlencode(bm)  :' . urlencode($bm) . "
\n";
echo 'urlencode(bstr):' . urlencode($bstr) . "
\n";

Statement:
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