PHP 랜덤생성하기 정보
PHP PHP 랜덤생성하기본문
mt_rand()를 이용하여 해당 길이만큼의 랜덤문자열을 생성하는 함수를 소개합니다.
function numeric($length)
{
$chars = "1234567890";
$clen = strlen( $chars )-1;
$id = '';
for ($i = 0; $i < $length; $i++) {
$id .= $chars[mt_rand(0,$clen)];
}
return ($id);
}
function alphabets($length)
{
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
$clen = strlen( $chars )-1;
$id = '';
for ($i = 0; $i < $length; $i++) {
$id .= $chars[mt_rand(0,$clen)];
}
return ($id);
}
function alphaNumeric($length)
{
$chars = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
$clen = strlen( $chars )-1;
$id = '';
for ($i = 0; $i < $length; $i++) {
$id .= $chars[mt_rand(0,$clen)];
}
return ($id);
}
function alphaNumericWithoutCase($length)
{
$chars = "1234567890abcdefghijklmnopqrstuvwxyz";
$clen = strlen( $chars )-1;
$id = '';
for ($i = 0; $i < $length; $i++) {
$id .= $chars[mt_rand(0,$clen)];
}
return ($id);
}
$length는 생성할 랜덤문자열 길이값입니다.!-->
추천
0
0
댓글 0개