PHP產生隨機字符串函數

  
  
           
  
  
  1. <?php  
  2. function random($length) {  
  3.     $hash = '';  
  4.     $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';  
  5.     $max = strlen($chars) - 1;  
  6.     mt_srand((double)microtime() * 1000000);  
  7.     for($i = 0; $i < $length$i++) {  
  8.         $hash .= $chars[mt_rand(0, $max)];  
  9.     }  
  10.     return $hash;  
  11. }  
  12. echo random(4); 
  13.  
  14. ?> 
相關文章
相關標籤/搜索