php:将包含 0..9a..f 的 varchar(32) 快速转换为 varchar ([log[38]16]+1)...0..9A..z
假设我们有一个字符串 md5('somestring')。它将包含符号 0..f。因此,char(32) 可以保存该哈希值,但我相信它不会超过 21 个字节 ([log 38/ log 236 + 1])*Length(hash)。有什么快速函数可以将符号 0..f 的字符串转换为符号 0..9A..z 的字符串吗? (这将需要超过 21 个字节,因为它只使用数字和拉丁字母)?
Suppose we have a string md5('somestring'). It will contain symbols 0..f. So, char(32) is OK to save that hash, but I beleive it could take no more than 21 bytes ([log 38/ log 236 + 1])*Length(hash). Any fast function to convert string with symbols 0..f into a string with symbols 0..9A..z? (which will take more than 21 bytes, because it uses only numbers and latin letters)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更好:以二进制形式散列结果。使用索引,二进制运行速度更快。
使用 mysql 创建一个字段
bin(16)
。查询如下:从 PHP 使用此函数(十六进制到 bin)
您还可以使用:
http://php.net/manual/en/function.hex2bin.php
http://php.net/manual/en/function.bin2hex.php
Better : hash the result in binary. Binary run faster and much more faster with indexes.
With mysql create a field
bin(16)
. Query are like this :From PHP Use this function (hex to bin)
You can also use :
http://php.net/manual/en/function.hex2bin.php
http://php.net/manual/en/function.bin2hex.php
将第二个参数设置为true:
Set the second parameter to true: