PHP產生隨機字符串函數
更新時間:2006年12月06日 00:00:00 作者:
<?php
/**
* 產生隨機字符串
*
* 產生一個指定長度的隨機字符串,并返回給用戶
*
* @access public
* @param int $len 產生字符串的位數
* @return string
*/
function randStr($len=6) {
$chars='ABDEFGHJKLMNPQRSTVWXYabdefghijkmnpqrstvwxy23456789#%*'; // characters to build the password from
mt_srand((double)microtime()*1000000*getmypid()); // seed the random number generater (must be done)
$password='';
while(strlen($password)<$len)
$password.=substr($chars,(mt_rand()%strlen($chars)),1);
return $password;
}
?>
/**
* 產生隨機字符串
*
* 產生一個指定長度的隨機字符串,并返回給用戶
*
* @access public
* @param int $len 產生字符串的位數
* @return string
*/
function randStr($len=6) {
$chars='ABDEFGHJKLMNPQRSTVWXYabdefghijkmnpqrstvwxy23456789#%*'; // characters to build the password from
mt_srand((double)microtime()*1000000*getmypid()); // seed the random number generater (must be done)
$password='';
while(strlen($password)<$len)
$password.=substr($chars,(mt_rand()%strlen($chars)),1);
return $password;
}
?>
相關文章
PHP判斷訪客是否手機端(移動端瀏覽器)訪問的方法總結【4種方法】
這篇文章主要介紹了PHP判斷訪客是否手機端(移動端瀏覽器)訪問的方法,結合實例形式總結分析了php基于HTTP_X_WAP_PROFILE、HTTP_VIA、HTTP_USER_AGENT、HTTP_ACCEPT等4種方法判斷訪客類型的相關操作技巧,需要的朋友可以參考下2019-03-03Windows下wamp php單元測試工具PHPUnit安裝及生成日志文件配置方法
這篇文章主要介紹了Windows下wamp php單元測試工具PHPUnit安裝及生成日志文件配置方法,簡明扼要的分析了Windows環(huán)境下wamp中php單元測試工具PHPUnit的安裝步驟、操作注意事項以及生成日志文件配置方法,需要的朋友可以參考下2018-05-05