Posted By

tasmanweb on 04/30/11


Tagged

php random function


Versions (?)

random alphanumeric text of length $codelength


 / Published in: PHP
 

  1. /*
  2. returns a random alphanumeric text of length $codelength (defaults to 4 characters)
  3. usage echo random_text(); or $output = random_text();
  4. 48 to 57 are the numbers
  5. 65 to 90 are UpperCase
  6. 97 to 122 are LowerCase
  7. */
  8. function random_text($code_length = 4){
  9. for($code_length, $newcode = ''; strlen($newcode) < $code_length; $newcode .= chr(!rand(0, 2) ? rand(48, 57) : (!rand(0, 1) ? rand(65, 90) : rand(97, 122))));
  10. return $newcode;
  11. }

Report this snippet  

You need to login to post a comment.