PHP生成随机或者唯一字符串
来源:互联网 发布:vb程序改错数字金字塔 编辑:程序博客网 时间:2024/06/06 18:04
本文出至:新太潮流网络博客
/** * [生成随机字符串] * @E-mial wuliqiang_aa@163.com * @TIME 2017-04-07 * @WEB http://blog.iinu.com.cn * @param integer $length [生成的长度] * @param integer $type [生成的类型] * @return [type] str [description] * @php 随机码类型:0,数字+大写字母;1,数字;2,小写字母;3,大写字母;4,特殊字符;-1,数字+大小写字母+特殊字符 */function randCode($length = 5, $type = 0) { $arr = array(1 => "0123456789", 2 => "abcdefghijklmnopqrstuvwxyz", 3 => "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 4 => "~@#$%^&*(){}[]|"); if ($type == 0) { array_pop($arr); $string = implode("", $arr); } else if ($type == "-1") { $string = implode("", $arr); } else { $string = $arr[$type]; } $count = strlen($string) - 1; for ($i = 0; $i < $length; $i++) { $str[$i] = $string[rand(0, $count)]; $code .= $str[$i]; } return $code;}/** * [生成唯一字符串] * @E-mial wuliqiang_aa@163.com * @TIME 2017-04-07 * @WEB http://blog.iinu.com.cn * @ 0-存数字字符串;1-小写字母字符串;2-大写字母字符串;3-大小写数字字符串;4-字符; * 5-数字,小写,大写,字符混合 * @param integer $type [字符串的类型] * @param integer $length [字符串的长度] * @param integer $time [是否带时间1-带,0-不带] * @return [string] $str [返回唯一字符串] */function randSole($type = 0,$length = 18,$time=0){ $str = $time == 0 ? '':date('YmdHis',time()); switch ($type) { case 0: for((int)$i = 0;$i <= $length;$i++){ if(mb_strlen($str) == $length){ $str = $str; }else{ $str .= rand(0,9); } } break; case 1: for((int)$i = 0;$i <= $length;$i++){ if(mb_strlen($str) == $length){ $str = $str; }else{ $rand = "qwertyuioplkjhgfdsazxcvbnm"; $str .= $rand{mt_rand(0,26)}; } } break; case 2: for((int)$i = 0;$i <= $length;$i++){ if(mb_strlen($str) == $length){ $str = $str; }else{ $rand = "QWERTYUIOPLKJHGFDSAZXCVBNM"; $str .= $rand{mt_rand(0,26)}; } } break; case 3: for((int)$i = 0;$i <= $length;$i++){ if(mb_strlen($str) == $length){ $str = $str; }else{ $rand = "123456789qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM"; $str .= $rand{mt_rand(0,35)}; } } break; case 4: for((int)$i = 0;$i <= $length;$i++){ if(mb_strlen($str) == $length){ $str = $str; }else{ $rand = "!@#$%^&*()_+=-~`"; $str .= $rand{mt_rand(0,17)}; } } break; case 5: for((int)$i = 0;$i <= $length;$i++){ if(mb_strlen($str) == $length){ $str = $str; }else{ $rand = "123456789qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM!@#$%^&*()_+=-~`"; $str .= $rand{mt_rand(0,52)}; } } break; } return $str;}本文出至:新太潮流网络博客
阅读全文
0 0
- PHP生成随机或者唯一字符串
- php生成唯一字符串
- PHP生成唯一字符串
- 随机生成密码或者字符串
- PHP生成随机字符串
- php 随机生成字符串
- php生成随机字符串
- php生成随机字符串
- php生成随机字符串
- php生成随机字符串
- php 生成随机字符串
- php 生成随机字符串
- PHP随机生成字符串
- php 生成随机字符串
- PHP生成随机字符串
- PHP生成随机字符串
- php随机生成字符串
- php 生成随机字符串
- PHP匹配当前传入是何种类型
- HTML界面怎么隐藏描述的多余部分
- nginx 配置
- open openat
- C语言中无符号数和有符号数之间的运算
- PHP生成随机或者唯一字符串
- Eclipse反编译插件JadClipse打包离线安装
- 关于<c:if >判断 char 类型
- xstream解析xml字符串和生成对象
- Andrew Ng机器学习笔记(三)
- WINAPI--解压缩函数
- PHP的CURL的POST/GET访问
- 查看临时表空间及大小
- Postman相关