Make random string

17 Ⅴ 2010

This is a tiny function that makes a random string of predefined length.
It does not use letters and numbers that could be confusing, like O and 0.

// Make a random string
function makeRandomString($length){
	$str = array('a', 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'W', 'X', 'Y', 'Z', '2', '4', '5', '6', '7', '8', '9');
	$nkeys = array_rand($str, $length);
	$nstr = '';
	foreach($nkeys as $key){ $nstr .= $str[$key]; }
	return $nstr;
}