php隨機字串 密碼產生

來源:互聯網
上載者:User

標籤:io   使用   ar   for   sp   art   c   on   cti   

  1. /** 
  2.  * @param string $len 長度 
  3.  * @param string $type 字串類型 
  4.  * 0 字母 1 數字 其它 混合 
  5.  * @param string $addChars 額外字元 
  6.  * @return string 
  7.  */  
  8. function leipi_rand_string($len=6,$type=‘‘,$addChars=‘‘) {  
  9.     $str =‘‘;  
  10.     switch($type) {  
  11.         case 0:  
  12.             $chars=‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz‘.$addChars;  
  13.             break;  
  14.         case 1:  
  15.             $chars= str_repeat(‘0123456789‘,3);  
  16.             break;  
  17.         case 2:  
  18.             $chars=‘ABCDEFGHIJKLMNOPQRSTUVWXYZ‘.$addChars;  
  19.             break;  
  20.         case 3:  
  21.             $chars=‘abcdefghijklmnopqrstuvwxyz‘.$addChars;  
  22.             break;  
  23.         case 4:  
  24.             $chars = "在這裡可以輸入一些隨機的中文".$addChars;  
  25.             break;  
  26.         default :  
  27.             // 預設去掉了容易混淆的字元oOLl和數字01,要添加請使用addChars參數  
  28.             $chars=‘ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789‘.$addChars;  
  29.             break;  
  30.     }  
  31.     if($len>10 ) {//位元過長重複字串一定次數  
  32.         $chars= $type==1? str_repeat($chars,$len) : str_repeat($chars,5);  
  33.     }  
  34.     if($type!=4) {  
  35.         $chars   =   str_shuffle($chars);  
  36.         $str     =   substr($chars,0,$len);  
  37.     }else{  
  38.         // 中文隨機字  
  39.         for($i=0;$i<$len;$i++){  
  40.           $str.= msubstr($chars, floor(mt_rand(0,mb_strlen($chars,‘utf-8‘)-1)),1);  
  41.         }  
  42.     }  
  43.     return $str;  
  44. }  

php隨機字串 密碼產生

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.