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)文章
php實(shí)現(xiàn)兩個(gè)數(shù)組相加的方法
這篇文章主要介紹了php實(shí)現(xiàn)兩個(gè)數(shù)組相加的方法,實(shí)例分析了php的數(shù)組運(yùn)算符+的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-02-02
PHP函數(shù)import_request_variables()用法分析
這篇文章主要介紹了PHP函數(shù)import_request_variables()用法,結(jié)合實(shí)例形式分析了import_request_variables函數(shù)的功能,定義及相關(guān)使用技巧,需要的朋友可以參考下2016-04-04
php堆排序?qū)崿F(xiàn)原理與應(yīng)用方法
這篇文章主要介紹了php堆排序?qū)崿F(xiàn)原理與應(yīng)用方法,較為詳細(xì)的分析了堆排序的原理及使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-01-01
php實(shí)現(xiàn)獲取本年,本月,本周時(shí)間戳和日期格式
這篇文章主要為大家詳細(xì)介紹了php實(shí)現(xiàn)獲取本年、本月、本周時(shí)間戳和日期格式的相關(guān)方法,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以學(xué)習(xí)一下2023-12-12
PHP中關(guān)鍵字interface和implements詳解
PHP 類是單繼承,也就是不支持多繼承,當(dāng)一個(gè)類需要多個(gè)類的功能時(shí),繼承就無能為力了,為此 PHP 引入了類的接口技術(shù)。下面這篇文章主要跟大家介紹了關(guān)于PHP中關(guān)鍵字interface和implements的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。2017-06-06

