LoginSignup
134
130

More than 5 years have passed since last update.

ランダムな英数字の文字列を作成

Last updated at Posted at 2014-06-05

最近、助かりましたってコメントをいただいたので、
前のブログから転載。

桁数が指定できて、これすごい便利!
ここで載ってました。
http://ameblo.jp/linking/entry-10289895826.html

/**
 * ランダム文字列生成 (英数字)
 * $length: 生成する文字数
 */
function makeRandStr($length) {
    $str = array_merge(range('a', 'z'), range('0', '9'), range('A', 'Z'));
    $r_str = null;
    for ($i = 0; $i < $length; $i++) {
        $r_str .= $str[rand(0, count($str) - 1)];
    }
    return $r_str;
}
134
130
9

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
134
130