duanben1324 2011-06-03 14:32
浏览 24
已采纳

字符串中的唯一编号 - php

I have some strings containing alpha numeric values, say

asdf1234,

qwerty//2345

etc..

I want to generate a specific constant number related with the string. The number should not match any number generated corresponding with other string..

  • 写回答

4条回答 默认 最新

  • dongqi4085 2011-06-03 14:35
    关注

    Does it have to be a number?

    You could simply hash the string, which would give you a unique value.

    echo md5('any string in here');
    

    Note: This is a one-way hash, it cannot be converted from the hash back to the string.

    This is how passwords are typically stored (using this or another hash function, typically with a 'salt' method added.) Checking a password is then done by hashing the input and comparing to the stored hash.

    edit: md5 hashes are 32 characters in length.

    Take a look at other hash functions:
    http://us3.php.net/manual/en/function.crc32.php (returns a number, possibly negative)
    http://us3.php.net/manual/en/function.sha1.php (40 characters)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题