-
function get_randomString($count=8, $rm_similar = false){
-
//create list of characters
-
-
$chars = array_flip(array_merge(range(0, 9), range('A', 'Z')));
-
-
// remove similar looking characters that might cause confusion
-
if ($rm_similar) {
-
unset($chars[0], $chars[1], $chars[2], $chars[5], $chars[8], $chars['B'],
-
$chars['I'], $chars['O'], $chars['Q'], $chars['S'], $chars['U'], $chars['V'], $chars['Z']);
-
}
-
-
// generate the string of random text
-
-
for( $i = 0, $text = ''; $i < $count; $i++ ) {
-
$text .= array_rand($chars);
-
}
-
return $text;
-
}
PHP, random
This entry was posted
on Wednesday, June 3rd, 2009 at 7:37 am and is filed under PHP.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.