Pages

Wednesday, December 30, 2015

Random alphabet in PHP

Change Snippet Background Color
          
            
               function RandomAlpha($len){
                  $key = "";
                  for($x=0;$x<$len;$x++)
                     $key .= chr(ord('A') rand(0,25));
                 
                  return $key;
               }
               function RandomAlphaNoDuplicate($len){
                  $key = "";
                   while(strlen($key) < $len){
                     $key .= chr(ord('A') rand(0,25));
                     $key = implode('',array_unique(str_split($key)));
                   }
                  return $key;
               }
               
                echo RandomAlphaNoDuplicate(12);
            
          
        

No comments:

Post a Comment