zoukankan      html  css  js  c++  java
  • 生成随机字符串 php

     1 /**
     2     +----------------------------------------------------------
     3     * 生成随机字符串
     4     +----------------------------------------------------------
     5     * @param int       $length  要生成的随机字符串长度
     6     * @param string    $type    随机码类型:0,数字+大小写字母;1,数字;2,小写字母;3,大写字母;4,特殊字符;-1,数字+大小写字母+特殊字符
     7     +----------------------------------------------------------
     8     * @return string
     9     +----------------------------------------------------------
    10     echo randCode(6,1);
    11 */
    12 function randCode($length = 32, $type = 0) {
    13     $arr = array(1 => "0123456789", 2 => "abcdefghijklmnopqrstuvwxyz", 3 => "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 4 => "~@#$%^&*(){}[]|");
    14     if ($type == 0) {
    15         array_pop($arr);
    16         $string = implode("", $arr);
    17     } elseif ($type == "-1") {
    18         $string = implode("", $arr);
    19     } else {
    20         $string = $arr[$type];
    21     }
    22     $count = strlen($string) - 1;
    23     $code = '';
    24     for ($i = 0; $i < $length; $i++) {
    25         $code .= $string[rand(0, $count)];
    26     }
    27     return $code;
    28 }
  • 相关阅读:
    【MySQL】自增步长调整
    【Python】异常
    【Python】单例模式
    rabbitMQ-server 下载地址
    函数(六)---内置函数
    # python04---函数
    python02---基础数据类型
    0001-代码仓库-git 命令
    0001-代码仓库-mvn
    腾讯短信接口使用
  • 原文地址:https://www.cnblogs.com/daixin/p/12978549.html
Copyright © 2011-2022 走看看