Created
January 20, 2012 11:51
-
-
Save justinkelly/1647016 to your computer and use it in GitHub Desktop.
Simple PHP function to generate a random apha-numeric code with only readable characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Simple PHP function to generate a random apha-numeric code with only readable characters | |
*/ | |
function randomCode($length=4) { | |
/* Only select from letters and numbers that are readable - no 0 or O etc..*/ | |
$characters = "23456789ABCDEFHJKLMNPRTVWXYZ"; | |
for ($p = 0; $p < $length; $p++) | |
{ | |
$string .= $characters[mt_rand(0, strlen($characters)-1)]; | |
} | |
return $string; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've forked your little function and added a possibility to get an array back with a desired amount of unique random codes. You find it here: https://gist.github.com/NoTeefy/fb830a3b385b2eb3bc58