PHP生成随机字符串
2022-06-06PHP
PHP二中方法,生成随机字符串。
一:MD5+时间戳生成32位随机字符串
/** * 获取32位随机字符串 * @return string */ public static function getRandKey() { return md5( time() . mt_rand(0, 99999999) ); }
二:从固定字符串循环随机取其中一位数拼接
/** * 获取32位随机字符串 * * @return string */ function getRandom(){ $str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ; $key = "" ; for ( $i =0; $i < 32 ; $i ++) { $key .= $str{mt_rand(0,32)}; } return $key ; }
很赞哦! ()