標籤:io for ar cti 時間 on sp php
1. 產生唯一的ID
uniqid();//不加首碼,產生的字串是13位,根據當前微妙的時間戳記
2. 隨機函數
/**
* 產生指定位元的隨機字串
*
* @param int $len 隨機字串長度
* @param bool $include_number 是否允許包含數字
*
*/
public static function make_rand_string($len, $include_number = false) {
$string_list = array (‘A‘, ‘B‘, ‘C‘, ‘D‘, ‘E‘, ‘F‘, ‘G‘, ‘H‘, ‘J‘, ‘K‘, ‘L‘, ‘M‘, ‘N‘, ‘P‘, ‘Q‘, ‘R‘, ‘S‘, ‘T‘, ‘U‘, ‘V‘, ‘W‘, ‘X‘, ‘Y‘, ‘Z‘, ‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘, ‘f‘, ‘g‘, ‘h‘, ‘j‘, ‘k‘, ‘m‘, ‘n‘, ‘p‘, ‘q‘, ‘r‘, ‘s‘, ‘t‘, ‘u‘, ‘v‘, ‘w‘, ‘x‘, ‘y‘, ‘z‘ );
$string_include_number_list = array (‘A‘, ‘B‘, ‘C‘, ‘D‘, ‘E‘, ‘F‘, ‘G‘, ‘H‘, ‘J‘, ‘K‘, ‘M‘, ‘N‘, ‘P‘, ‘Q‘, ‘R‘, ‘S‘, ‘T‘, ‘U‘, ‘V‘, ‘W‘, ‘X‘, ‘Y‘, ‘Z‘, ‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘, ‘f‘, ‘g‘, ‘h‘, ‘j‘, ‘k‘, ‘m‘, ‘n‘, ‘p‘, ‘q‘, ‘r‘, ‘s‘, ‘t‘, ‘u‘, ‘v‘, ‘w‘, ‘x‘, ‘y‘, ‘z‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘, ‘7‘, ‘8‘, ‘9‘ );
if ($include_number) {
$arr = $string_include_number_list;
} else {
$arr = $string_list;
}
$rand_max = count ( $arr ) - 1;
$return_string = null;
for($i = 0; $i < $len; $i ++) {
$rand = mt_rand ( 0, $rand_max );
$return_string .= $arr [$rand];
}
return $return_string;
}
3. 寫的再亂 也要堅持寫部落格