dp0518 2014-10-14 16:02
浏览 14
已采纳

将唯一字符串与较短的唯一字符串匹配

Let say I have to manage 1,000,000 phone numbers which are in 12-digit format. Certainly, they are distinguish. Now I want to assign to each number a shorter string (7 alphanumeric - case sensitive characters) that must be also distinguish. What would be the best solution using Php?

  • 写回答

1条回答 默认 最新

  • 普通网友 2014-10-14 16:09
    关注

    You can use PHP's base_convert() function to change integers into strings.

    From integer to a-z0-9 base 36 string: $shortString = base_convert($phoneNumber, 10, 36);

    From base 36 string to integer: $phoneNumber = base_convert($shortString, 36, 10);

    If that's not short enough and you want to use the full gamut of a-zA-Z0-9 characters, you'll need to use a custom function to convert to base 62. There are some great ones at http://php.net/base_convert.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据