/*函數-生成隨機字符串, $num,指定生成位數, $similar 是否包含類似字符 $type 字符類型 true 大寫.false 小寫 */ function randText($num,$type = false,$similar = false){ //組合 $chars = array(); $chars = array_flip(array_merge(range(0,9),range('a','z'))); if($similar === false){ //去掉類似 unset($chars[0],$chars[1],$chars[2],$chars[5],$chars[8],$chars['b'],$chars['i'],$chars['o'],$chars['q'],$chars['s'],$chars['u'],$chars['v'],$chars['v']); } //進行遍歷 for($i = 0; $i < $num; $i++ ){ $str .=array_rand($chars); } if($type === true){ $str = strtoupper($str); } return str_shuffle($str); }