PHP生成唯一的字符串 [英] PHP generate a unique string

查看:318
本文介绍了PHP生成唯一的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个表中有一个ID列,用于存储行ID号(自动递增),例如1、2、3.我想生成一个随机且唯一的字符串,该字符串只能包含数字,字母和破折号(- )和下划线(_).字符串的长度应为4-6,并且应该是唯一的.有人可以帮助我如何产生吗?谢谢.

I have an ID column in a table which stores the row ID number (auto increment), For example 1, 2, 3. I want to generated a random and unique string which could contain only numbers, alphabets and dash (-) and underscore (_). The length of string should be 4-6, and it should be unique. Can someone help me how to generate? thanks.

推荐答案

使用它-base_convert(mt_rand(0x1D39D3E06400000,0x41C21CB8E0FFFFFF),10,36),但要针对db检查新值.

Use this - base_convert(mt_rand(0x1D39D3E06400000, 0x41C21CB8E0FFFFFF), 10, 36), but check new value against db.

这篇关于PHP生成唯一的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆