PHP 랜덤생성하기
mt_rand()를 이용하여 해당 길이만큼의 랜덤문자열을 생성하는 함수를 소개합니다.
[code]
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);
}
[/code]
$length는 생성할 랜덤문자열 길이값입니다.
게시판 목록
개발자팁
개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 5366 | 기타 |
nekoieye
|
1년 전 | 1119 | |
| 5365 | PHP | 1년 전 | 775 | ||
| 5364 | JavaScript | 1년 전 | 527 | ||
| 5363 | JavaScript | 1년 전 | 994 | ||
| 5362 | 1년 전 | 1233 | |||
| 5361 | JavaScript | 1년 전 | 1241 | ||
| 5360 |
그누보드이해하기
|
1년 전 | 777 | ||
| 5359 | 1년 전 | 1091 | |||
| 5358 | 1년 전 | 1095 | |||
| 5357 | 1년 전 | 809 | |||
| 5356 | 1년 전 | 367 | |||
| 5355 |
|
1년 전 | 586 | ||
| 5354 | 1년 전 | 1062 | |||
| 5353 |
|
1년 전 | 705 | ||
| 5352 |
|
1년 전 | 640 | ||
| 5351 | PHP | 1년 전 | 809 | ||
| 5350 | PHP | 1년 전 | 574 | ||
| 5349 | OS | 1년 전 | 647 | ||
| 5348 | 기타 | 1년 전 | 450 | ||
| 5347 | 기타 | 1년 전 | 633 | ||
| 5346 | 기타 | 1년 전 | 505 | ||
| 5345 | 기타 | 1년 전 | 400 | ||
| 5344 | JavaScript |
|
1년 전 | 430 | |
| 5343 | PHP |
|
1년 전 | 501 | |
| 5342 | jQuery | 1년 전 | 575 | ||
| 5341 | PHP |
|
1년 전 | 880 | |
| 5340 | Mobile |
슈퍼스타맨
|
1년 전 | 560 | |
| 5339 | 기타 |
|
1년 전 | 561 | |
| 5338 |
멀티트리플
|
2년 전 | 1297 | ||
| 5337 | 기타 |
슈퍼스타맨
|
2년 전 | 1792 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기