代码如下:
<?php
/*
* 生成随机字符串
* @param int $length 生成随机字符串的长度
* @param string $char 组成随机字符串的字符串
* @return string $string 生成的随机字符串
*/
function str_rand($length = , $char = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
if(!is_int($length) || $length < ) {
return false;
} $string = '';
for($i = $length; $i > ; $i--) {
$string .= $char[mt_rand(, strlen($char) - )];
} return $string;
} echo str_rand(),"<br />"; /*
* 生成32位唯一字符串
*/
$uniqid = md5(uniqid(microtime(true),true));
echo $uniqid;