Skip to content

Instantly share code, notes, and snippets.

@focustrate
Created October 26, 2012 20:10
Show Gist options
  • Select an option

  • Save focustrate/3961183 to your computer and use it in GitHub Desktop.

Select an option

Save focustrate/3961183 to your computer and use it in GitHub Desktop.
Random string generator
<?php
$use_upper = true;
$use_lower = true;
$use_digits = true;
$use_symbols = true;
$string_length = 24;
$letters = 'abcdefghijklmnopqrstuvwxyz';
$digits = '1234567890';
$symbols = '~`!@#$%^&*()_-+={[}]|\\;:"\'<,>.?/';
$rand_string = '';
if($use_upper) {
$rand_string .= strtoupper($letters);
}
if($use_lower) {
$rand_string .= $letters;
}
if($use_digits) {
$rand_string .= $digits;
}
if($use_symbols) {
$rand_string .= $symbols;
}
$rand_string_length = strlen($rand_string)-1;
$output = '';
for($i=0;$i<$string_length;$i++) {
$index = rand(0,$rand_string_length);
$output .= $rand_string[$index];
}
echo $output;
echo "\n\n";
?>
@focustrate
Copy link
Copy Markdown
Author

hacked up real quick. does the job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment