PHP產(chǎn)生隨機(jī)字符串函數(shù)
更新時(shí)間:2006年12月06日 00:00:00 作者:
<?php
/**
* 產(chǎn)生隨機(jī)字符串
*
* 產(chǎn)生一個(gè)指定長度的隨機(jī)字符串,并返回給用戶
*
* @access public
* @param int $len 產(chǎn)生字符串的位數(shù)
* @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;
}
?>
/**
* 產(chǎn)生隨機(jī)字符串
*
* 產(chǎn)生一個(gè)指定長度的隨機(jī)字符串,并返回給用戶
*
* @access public
* @param int $len 產(chǎn)生字符串的位數(shù)
* @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;
}
?>
相關(guān)文章
微信公眾平臺(tái)消息接口校驗(yàn)與消息接口響應(yīng)實(shí)例
這篇文章主要介紹了微信公眾平臺(tái)消息接口校驗(yàn)與消息接口響應(yīng)的方法,實(shí)例分析了微信公眾平臺(tái)開發(fā)的具體步驟及wechatCallbackapiTest等類的用法,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-12-12PHP的autoload機(jī)制的實(shí)現(xiàn)解析
在使用PHP的OO模式開發(fā)系統(tǒng)時(shí),通常大家習(xí)慣上將每個(gè)類的實(shí)現(xiàn)都存放在一個(gè)單獨(dú)的文件里,這樣會(huì)很容易實(shí)現(xiàn)對(duì)類進(jìn)行復(fù)用,同時(shí)將來維護(hù)時(shí)也很便利2012-09-09PHP判斷訪客是否手機(jī)端(移動(dòng)端瀏覽器)訪問的方法總結(jié)【4種方法】
這篇文章主要介紹了PHP判斷訪客是否手機(jī)端(移動(dòng)端瀏覽器)訪問的方法,結(jié)合實(shí)例形式總結(jié)分析了php基于HTTP_X_WAP_PROFILE、HTTP_VIA、HTTP_USER_AGENT、HTTP_ACCEPT等4種方法判斷訪客類型的相關(guān)操作技巧,需要的朋友可以參考下2019-03-03Windows下wamp php單元測試工具PHPUnit安裝及生成日志文件配置方法
這篇文章主要介紹了Windows下wamp php單元測試工具PHPUnit安裝及生成日志文件配置方法,簡明扼要的分析了Windows環(huán)境下wamp中php單元測試工具PHPUnit的安裝步驟、操作注意事項(xiàng)以及生成日志文件配置方法,需要的朋友可以參考下2018-05-05PHP合并數(shù)組函數(shù)array_merge用法分析
這篇文章主要介紹了PHP合并數(shù)組函數(shù)array_merge用法,結(jié)合實(shí)例形式分析了php數(shù)組合并函數(shù)array_merge的具體功能、使用方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2017-02-02