- strtoupper: documentation ( source)
- rand: documentation ( source)
<?php
function randomString($length=10,$symbols=false) {
$grabbag = "abcdefghijklmnopqrstuvwxyz0123456789";
if ($symbols) {
$grabbag .= '!@#$%^&*()_+{}-=[]|\\:";\'<,>.?/~`';
}
$string = '';
$len = strlen($grabbag)-1;
while ($length--) {
$char = $grabbag[rand(0,$len)];
if (rand(0,1)) {
$char = strtoupper($char);
}
$string .= $char;
}
return $string;
}
echo randomString(20);