网络营销电子商务研究中心

网络营销电子商务研究中心 (https://www.0058.net/index.php)
-   代码交流 (https://www.0058.net/forumdisplay.php?f=16)
-   -   php随机生成字符串函数,可指定长度 (https://www.0058.net/showthread.php?t=2996)

yahoo 2008-02-01 12:03 PM

php随机生成字符串函数,可指定长度
 
/*随机生成字符串函数random
$length生成字符串的长度
*/
function random($length) {
$hash = '';
$chars = '0123456789';
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
return $hash;
}

echo random(6);


All times are GMT +8. The time now is 03:35 AM.

Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.