PHP 產生指定長度的亂數字串,數字
function randomStr($length) { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $result = ''; for ($i = 0; $i < $length; $i++) { $result .= $chars[ mt_rand(0, strlen($chars) - 1) ]; } return $result; } function randomNum($length) { $result = ''; for ($i = 0; $i < $length; $i++) { $result .= mt_rand(0, 9); } return $result; }