Forum Moderators: coopster
$letters = range('a','z');
Then for random string, loop and use rand as mentioned by d40sithui.
$howmany = '20';
$string = '';for ($i=0; $i<$howmany; $i++)
{
$string .= $letters[rand(0,25)];
}echo $string;
dc
$howmany = '20';
$newpass = '';
for ($i = 0; $i < $howmany; $i++) {
$randval = rand(97,122);
$newpass .= chr($randval);
}
echo $newpass;
or how about numbers and letters
$howmany = '20';
$newpass = '';
for ($i = 0; $i < $howmany; $i++) {
$randval = rand(48,83);
if ($randval > 57) { $randval = $randval + 39; }
$newpass .= chr($randval);
}
}
echo $newpass;
$random_string_len = 10;
$source = "23456789"; //no 1
$source .= "abcdefghijkmnopqrstuvwxyz"; //no small L (l) because of its resemblance with 1
$source .= "ABCDEFGHJKLMNPQRSTUVWXYZ"; //no I because of resemblance to 1
srand ((double) microtime() * 1000000);
$result = '';
while ( $random_string_len )
{
$result .= substr($source, rand( 0, strlen( $source )), 1);
$random_string_len--;
}
echo $result;