PHP 隨機生成字符串

/**

  • 隨機生成字符串
    */
    function randCode($length=5,$type=0){
    $arr = array(1 => "0123456789", 2 => "abcdefghijklmnopqrstuvwxyz", 3 => "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 4 => "~@#$%^&
    (){}[]|");
    if ($type == 0){
    array_pop($arr);
    $string = implode("", $arr);
    }elseif($type == "-1"){
    $string = implode("", $arr);
    }else{
    $string = $arr[$type];
    }
    $count = strlen($string) - 1;
    $code = '';
    for($i = 0; $i < $length; $i++){
    $code .= $string[rand(0, $count)];
    }
    return $code;
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章